printmedia
asked on
Textbox content not evaluated as number but as string in vb.net windows form
Hi all.
I have a windows form that has various textboxes, two of these textboxes are for entering quantities. Below is a portion of the script that does a comparison between both textboxes, what I'm realizing is that it is not comparing them as numbers but as string. When txtQty4.Text is 999 and txtQty2 is 1000 the comparison fails and it shouldn't.
How can I get it to treat them as numbers? Thank you in advance.
I have a windows form that has various textboxes, two of these textboxes are for entering quantities. Below is a portion of the script that does a comparison between both textboxes, what I'm realizing is that it is not comparing them as numbers but as string. When txtQty4.Text is 999 and txtQty2 is 1000 the comparison fails and it shouldn't.
How can I get it to treat them as numbers? Thank you in advance.
ElseIf txtQty4.Text <= txtQty2.Text Then
txtQty3.Text = Nothing
txtQty4.Text = Nothing
txtQty5.Text = Nothing
txtQty6.Text = Nothing
txtQty7.Text = Nothing
txtQty8.Text = Nothing
txtQty9.Text = Nothing
txtQty10.Text = Nothing
txtPrice2.Text = Nothing
txtPrice3.Text = Nothing
txtPrice4.Text = Nothing
txtPrice5.Text = Nothing
txtQty4.Enabled = False
txtQty6.Enabled = False
txtQty8.Enabled = False
txtQty10.Enabled = False
txtPrice2.Enabled = False
txtPrice3.Enabled = False
txtPrice4.Enabled = False
txtPrice5.Enabled = False
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thanks for points!
Happy coding!
Happy coding!
However, be aware that Integer is not the only type of data that has a TryParse. All the base types (Integer, Double, Date) have a TryParse, that make the distinction between what the different types accept.
For instance, if your quantity must never be negative and is never higher than 255, Byte.TryParse might be more interesting because it will not accept negative values, while Integer.TryParse will.