4 Replies - 2654 Views - Last Post: 17 July 2010 - 11:41 AM Rate Topic: -----

#1 vennesschan  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 112
  • Joined: 20-April 10

Conversion from string "" to type 'Double' is not vali

Posted 16 July 2010 - 04:07 PM

Hi,

Can someone tell me why I got the following (InvalidCastException was unhandled) on the following code and how can I solve the problem.

 LabelPB.Text = P - Total.Text 'Conversion from string "" to type 'Double' is not valid



Thank you.
Is This A Good Question/Topic? 0
  • +

Replies To: Conversion from string "" to type 'Double' is not vali

#2 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2216
  • View blog
  • Posts: 9,352
  • Joined: 29-May 08

Re: Conversion from string "" to type 'Double' is not vali

Posted 16 July 2010 - 04:13 PM

Because a string is not double, even if it contains only digits.
Was This Post Helpful? 0
  • +
  • -

#3 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 463
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: Conversion from string "" to type 'Double' is not vali

Posted 16 July 2010 - 04:23 PM

actually it is because your string is empty.
'Conversion from string "" to type 'Double' is not valid

EDIT: you can always check if the box is empty
If Not Total.Text="" Then
       LabelPB.Text = P - Total.Text
End If


:)

This post has been edited by NoBrain: 16 July 2010 - 04:28 PM

Was This Post Helpful? 0
  • +
  • -

#4 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4316
  • View blog
  • Posts: 7,485
  • Joined: 08-June 10

Re: Conversion from string "" to type 'Double' is not vali

Posted 16 July 2010 - 04:46 PM

I personally prefer not to use implicit casts. I would use Double.TryParse to check if the text is a valid number.
Was This Post Helpful? 0
  • +
  • -

#5 dbasnett  Icon User is offline

  • D.I.C Addict

Reputation: 102
  • View blog
  • Posts: 584
  • Joined: 01-October 08

Re: Conversion from string "" to type 'Double' is not vali

Posted 17 July 2010 - 11:41 AM

Agree with insertalias. If all else fail read the destruction's, I mean instructions.

Double.TryParse Documentation
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1