Skip to main content
GameDev.net gamedev.net
🔒 Locked

Visual Basic problem using Val

Started by thomashun Dec 3, 2001 at 11:17 AM 2 replies 300+ views
Original Post
thomashun
thomashun
I''m having a Val issue at the moment. lets say GuitarCost = price * quantity. Where do I put the val so if someone puts an ''a'' or something it turns it to 0.
BlueMonk
BlueMonk
Put Val around any data that is typed in. For instance:
GuitarCost = Val(txtPrice.Text) * Val(txtQuantity.Text)

"All you need to do to learn circular logic is learn circular logic"
"All you need to do to learn circular logic is learn circular logic"
wah_on_2
wah_on_2
The use of Val(str) as double
It is use to capture the numeric value in a string.

like:
dim str as string
dim num as integer

str = "1234"
num = val(str) + 10 ''num=1244

str = "123a"
num = val(str) + 10 ''num=133

str = "12a3"
num = val(str) + 10 ''num=22

in your case, i think is that:
GuitarCost = val(price) * val(quantity)
thomashun
thomashun
Thanks for the help on the mental lapse I had.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.