• Log in or sign up for an account here: https://www.sythe.org/login

How do I make a msg box come up on an error?

Visual Basic Matt

Apprentice
Joined
Jan 29, 2008
Sythe Gold
56
Messages
647
Location
Evurar
Ok, I am working on hiscore lookup. It work's fine. The problem is, is that when you type in an invalid username. (Does not feature in the hiscores) You get the error,
Code:
Run-time error '9':
Subscript out of range
I don't need to fix the error just need to make a msgbox come up (Username) Does not feature in the high scores. So basicly instead of the vb error box,
Code:
Run-time error '9':
Subscript out of range
A msg box
Code:
MsgBox (txtUsername.Text) + " does not feature in the hiscores!", vbCritical = vbOKOnly, "Oops!": Exit Sub
I am almost 100% sure that their is somthing like,
Code:
Private sub cmdLookup()
If txtUsername.Text = "" Then
MsgBox "You can't leave the username feild empty!"
Else
    lstHighscores.Clear
    getHighscores txtUsername.Text
End if
on error (9) goto featureerror
End sub
Public Sub featureerror()
MsgBox (txtUsername.Text) + " does not feature in the hiscores!", vbCritical = vbOKOnly, "Oops!": Exit Sub
End Sub

Thank's for all your help :)
 
To be honest, you should fix the error. Just working around errors is sloppy work (i do it myself sometimes out of laziness).

But to make an errorhandler this is how you do it:
Code:
Private Sub Command1_Click()
  On Error GoTo errorhandler

  'all your code goes here

  Exit Sub 'If it is a function you must put "Exit Function" instead.
errorhandler:
  MsgBox "An error has occurred!" & vbnewline & "Error Number: " & err.number & vbnewline & "Error Description: " & err.description,vbexclamation,"Error!"
  Resume Next 'This peice of code will resume the next line of code after the error has occurred. In your case its probably better to leave it out.
End Sub

I'm not going to do it for you, so hopefully you will learn the basics:
 
Runescape Gamblingrunescape gambling
Back
Top