If box.text = "" then cancel events

Lanc1988

Contributor
Joined
Nov 27, 2003
Messages
508
I have a button and two textboxes on my form.. what would the code be to cancel the rest of the events for the button if either one of the boxes is left blank?

I know to use something like the following:
Visual Basic:
If textbox1.text = "" Then
'cancel code
End If

If textbox2.text = "" Then
'cancel code
End If
But I just don't know what code to use to cancel (or stop) the rest of the events from happening.. i tried using "e.cancel" but I think that only works to stop a form from closing or something.
 
nevermind.. i think i would rather it just set a "0" in the two text boxes.. much easier and i think it would work better for me.. thanks.
 
To 'stop' code from executing, you put it in an If block.
If TextBox1.Text.Length > 0 AndAlso TextBox2.Text.Length > 0 Then

If you don't know how to invert the condition that you are checking, just put all of the code into the Else block. :)
 
Back
Top