Results 1 to 4 of 4

Thread: Stop command execution and restore to initial state?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    76

    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

  2. #2
    Fanatic Member
    Join Date
    Aug 2009
    Posts
    540

    Re: Stop command execution and restore to initial state?

    vb Code:
    1. If numCheckV = False OrElse TextBox1.Text = "" Then
    2. MsgBox("Please enter voltage!")
    3. Exit Sub
    4. 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

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    76

    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?

  4. #4
    Fanatic Member
    Join Date
    Aug 2009
    Posts
    540

    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:
    1. If numCheckV = False OrElse TextBox1.Text = "" Then
    2.    MsgBox("Please enter voltage!")
    3.    If TextBox1.Text = String.Empty Then
    4.       Textbox1.Focus()
    5.       Textbox1.SelectAll()
    6.    End If
    7.    Exit Sub
    8. 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
  •  



Click Here to Expand Forum to Full Width