Dorine Mae Dorine Mae - 6 months ago 31
Vb.net Question

VB.net: show a text depends on the answer

I'm not sure what went wrong here:





Dim xapp As Integer = 20000
Dim xnet As Integer
Dim ans As String

xnet = NETPAYTextBox.Text
ans = AppstatusTextBox.Text

If (xapp < xnet) Then
ans = "Approved"
Else
ans = "Pending"
End If






It suppose to show "Approved" if the value of the NETPAYTextBox is greater than 20000 or else it will show "Pending" if the value of the NETPAYTextBox is lower than 20000. Please help, it's simple but I'm really confused. Thanks by the way.

Answer

This should do the trick. It makes sure you have an Integer and if so do the comparison and set the text depending on the outcome...

    Dim xnet As Integer = 0

    AppstatusTextBox.Text = CStr(If(Integer.TryParse(NETPAYTextBox.Text, xnet) AndAlso 20000 < xnet, "Approved", "Pending"))
Comments