Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to stop the app 2

Status
Not open for further replies.

Biocide

Programmer
Joined
Oct 12, 2005
Messages
12
Location
SE
I want to stop the application if i have an error
Like this:
On a button
If textbox1 > 1 then
X = 1
Else Msgbox ("bla")

So if textbox isnt bigger than 1 the Msgbox shows and next part of my code starts.
But i want it to stop (not close the form) and start again when the user hits the button again to check if textbox is bigger than one this time
How do i do that?
 
You could simply use Exit Sub e.g.
Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        If CInt(TextBox1.Text) < 1 Then
            ' Show Error
            Exit Sub
        End If

        ' Rest of code goes here
    End Sub
You'll also have to check that the Text in the Textbox is actually an Integer for the above to work correctly.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Do you mean exit the application or re-focus the cursor to the textbox?

Application.Exit exits the application


If CInt(textbox1.Text) > 1 Then
X = 1
Else
MessageBox.Show("Error message")
TextBox1.Focus
End If

re-focuses the cusor to the textbox


Hope this helps.


[vampire][bat]
 
Thank you for youre answers it helped
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top