VB ?

15 pts.
Tags:
VB
VB 2008
Visual Basic
Visual Basic 2008
First VB class, can someone tell me the error in this code?

Dim sngNum1 As Single

Dim sngNum2 As Single

Dim sngSum As Single

sngNum1 = txtNum1.Text

sngNum2 = txtNum2.Text

sngSum = sngNum1 + sngNum2

lblSum.Text = sngSum.ToString



Software/Hardware used:
VB 2008

Answer Wiki

Thanks. We'll let you know when a new response is added.

This looks like a puzzle…

Why don’t you tell us what is the error message you are getting, and what is the line where you are getting it ?

If your text boxes are empty, you will get an error because a null string cannot be converted to a Single.

Discuss This Question: 2  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Jcbartnik
    Thanks. Actually I have not even coded it. This is question from a take home test for an intro to VB class. I have not written code in over 13 years and have gone back to finish my degree. The multiple choice answers are: a) A local variable is misplaced. b) A conversion funtion such as CSng was not used. c) The variable name sngNum1 was misspelled. d) The sngSum variable was declared as the wrong data type. VB is trully amazing compared to the procedure code I used to write. Thanks for the help.
    15 pointsBadges:
    report
  • carlosdl
    Well, it is not a good idea to post your homework questions here. You will learn a lot more by coding and solving it by yourself. Regards,
    68,330 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following