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

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)]

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

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

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

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.