2 Replies - 267 Views - Last Post: 26 June 2013 - 04:08 PM Rate Topic: -----

#1 Mucca  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 24-May 13

Hiscore Entry error

Posted 26 June 2013 - 02:28 PM

What is wrong with this code, it says
"Conversion from string "blah balah - " to type 'Double' is not valid."

Entry = txtFirst.Text + " " + txtLast.Text + " Bedroom/s - " + cbBedroom.SelectedIndex + " Night/s - " + nudNight.Value + " Week/s - " + nudWeek.Value

Is This A Good Question/Topic? 0
  • +

Replies To: Hiscore Entry error

#2 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: Hiscore Entry error

Posted 26 June 2013 - 03:40 PM

View PostMucca, on 26 June 2013 - 03:28 PM, said:

What is wrong with this code, it says
"Conversion from string "blah balah - " to type 'Double' is not valid."

Entry = txtFirst.Text + " " + txtLast.Text + " Bedroom/s - " + cbBedroom.SelectedIndex + " Night/s - " + nudNight.Value + " Week/s - " + nudWeek.Value

You still haven't turned on Option Strict, have you? This should be the very first thing you do in ANY program you are writing. In fact, you can make it be on permanently using Project->Properties.

I am not entirely sure what all your controls are, but essentially, it looks like you are trying to add text and numeric values. In fact, you are concatenating txtFirst.Text, txtLast.Text, and adding cbBedroom.SelectedIndex, nudNight.Value, and nudWeek.Value, all interspersed with literal text. Concatenating and adding are different operations, and require different variable types.

You should get out of the habit of letting the compiler try to figure out what types of data you are using and what you want to do with it. If you want to add something to something else, make sure they are the correct data types. If you want to concatenate something to something else, make sure they are the right data type.

Turn on Option Strict and fix all the problems that will be shown by little wiggly underlines in the code. You will save a TON of work and several tons of debugging and scratching your head.

Check the link in my signature about Option Strict.

This post has been edited by lar3ry: 26 June 2013 - 03:42 PM

Was This Post Helpful? 1
  • +
  • -

#3 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3623
  • View blog
  • Posts: 12,511
  • Joined: 12-December 12

Re: Hiscore Entry error

Posted 26 June 2013 - 04:08 PM

You should also use & to concatenate strings, reserve + for addition.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1