I am a begginer in vb.net. Actually i am having problems to do my homework. I will be posting both the question and my answer.
Question
Create a small program that allows you to enter a number. If the number is greater than 100, you will see the "You win a lucky prize" statement in a message box. Else if the number is less that 100, the message box displays “Better luck next time”.
Answer
Private Sub TxtNum_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxtNum.TextChanged
Dim Num As Integer
If Num > 100 Then
MsgBox("You win a lucky prize")
ElseIf Num < 100 Then
MsgBox("Better luck next time")
End If
End Sub
End Class
My problem
When i debug the database my form appears but however when i enter a number lets say zero in the textbox the following message is displayed "Better Luck next time". The textbox is not working for two digit numbers or three digit numbers. And neither is the condition if (Num > 100) working. Can u plz explain as to what is wrong in my code.
By using text changed you are checking everytime a new character is entered. So the first character entered is 1 and you get a <100. The next character makes it a 10 so it is still less than 100. If the next character is a 0 you get a 100 so it doesn't do any thing. Instead use a button click event and I would use <100 and >=100.
Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.
This thread is more than three months old
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.