Stop command execution and restore to initial state?
Hi I am checking to see if a textbox contains a number, or is null. If it is non numeric or null a message box appears asking the user to input the proper value. When the user clicks OK on the msgbox the program will continue to execute the code. I want it to stop executing the code and revert back to its default state as it would be if you just opened the program. What is the command for doing this so I can add to the if statement?? Thanks for your help!
Dim numCheckV as boolean
numCheckV = IsNumeric(Vinput)
If numCheckV = False OrElse TextBox1.Text = "" Then
MsgBox("Please enter voltage!")
End If
Re: Stop command execution and restore to initial state?
vb Code:
If numCheckV = False OrElse TextBox1.Text = "" Then
MsgBox("Please enter voltage!")
Exit Sub
End If
Will exit your sub if the message box code is hit.
EDIT: Do you have a sub that loads your data for you? if so, just call that sub before you exit and it should re-populate your form (although since you posted no code for it I have no idea how your program operates)
Double edit: Maybe it would be better to test which box had the bad input, and then set the focus to that box? This would prevent the user from having to fill out the form again to fix one mistake.
Re: Stop command execution and restore to initial state?
Thanks for that command!! Right now I just started playing around with GPIB and VB so I don't have to many inputs yet. In the future though when there are more user defined inputs on my form I will want to change it to function like you said. How do you set the focus for an individual text box so they wouldn't have to fill out the entier form again?
Re: Stop command execution and restore to initial state?
Just test the text box for an empty value, if it's empty then use the Focus() method of the text box to put the cursor in the box and the selectall() method to highlight anything in there (helps bring attention to where the problem is)
vb Code:
If numCheckV = False OrElse TextBox1.Text = "" Then
MsgBox("Please enter voltage!")
If TextBox1.Text = String.Empty Then
Textbox1.Focus()
Textbox1.SelectAll()
End If
Exit Sub
End If