0

Hi im really new to VB and am stuck on an IF statement, heres my code:

If TextBox12.Text >= 105.01 Then
TextBox16.Text = TextBox12.Text - 105.01 * 0.128
ElseIf TextBox12.Text < 105.01 Then
TextBox16.Text = "Not NI Eligible"

End If

When i debug it the error System.InvalidCastException is displayed four times for this bit of code.

textbox12.text is defined as a decimal within this Private sub buttonclick is that makes a difference

Any help on this would be appreciated
Thanks
Bagleys

2
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by Bagleys
0

hi
first u need to declare a variable of type decimal example:
dim number as deciamal
and then convert it to decimal as all textbox inputs are strings
[number=decimal.parse(textbox.text)]

0

and use try and catch to catch any exception such as invalid input

try
number=decimal.parse(textbox.text)
cath
msgbox(ex.tostring)
end try

0

Hi thanks for the quick reply

That seems to be working as it now displays the a number if the textbox12 is over 105.01 and the text if its not; but i still get the errors System.InvalidCastException any ideas?

Thanks
Bagleys

0

The code is:

Dim number As Decimal
number = 105.01
[number] = Decimal.Parse(TextBox16.Text)
If TextBox12.Text >= 105.01 Then
TextBox16.Text = TextBox12.Text - 105.01 * 0.128
ElseIf TextBox12.Text < 105.01 Then
TextBox16.Text = "Not NI Eligible"

End If

0

Hi sorry im very new to VB. Thanks very much for your help its working now.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.