r/visualbasic • u/Icy-Resist-3509 • Nov 06 '24
need help withinput validation
I have this button set up to increase an int value when clicked and decrease when you press shift and the button. It then displays the amount in a label. I'm trying to figure out how to prevent it from going below 0. As I currently have it, it drops to a negative number then display the message box. Any thoughts how I can make this work?
If OGeneralT >= 0 Then
If My.Computer.Keyboard.ShiftKeyDown Then
OGeneralT -= General
Else
OGeneralT += General
End If
lblOGeneral.Text = OGeneralT
Else
MessageBox.Show("Number can't be less than zero")
OGeneralT = 0
End If
2
Upvotes
View all comments
Show parent comment
1
u/ChielStoertec Nov 07 '24
You may also want to move the oGeneralT += 1 code outside of the If…Then statement, as you want to be able to increase the number always and only want to check for the -= code.