|
-
Nov 24th, 2009, 05:28 PM
#1
Thread Starter
Lively Member
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
-
Nov 24th, 2009, 05:31 PM
#2
Fanatic Member
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.
Where I'm from we only have one bit of advice for new comers: "If you hear banjos, turn and run".
VS 2008 .NetFW 2.0
-
Nov 24th, 2009, 05:58 PM
#3
Thread Starter
Lively Member
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?
-
Nov 25th, 2009, 10:22 AM
#4
Fanatic Member
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
Where I'm from we only have one bit of advice for new comers: "If you hear banjos, turn and run".
VS 2008 .NetFW 2.0
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|