|
-
Nov 5th, 2001, 10:46 AM
#1
Thread Starter
Addicted Member
on error goto
what's the difference between
Code:
on error goto ErrH:
and
-
Nov 5th, 2001, 10:47 AM
#2
Frenzied Member
I believe on Error goto ErrH: is a label
on error goto Errh is a statement.
-
Nov 5th, 2001, 10:48 AM
#3
None!
A label that you jump to must look like this.
LabelName:
With the colon but at the goto part the colon can be omitted.
-
Nov 5th, 2001, 10:48 AM
#4
Both are supported, and both will work.
The colon typically, however, denotes a label to which the sub or function should branch.
-
Nov 5th, 2001, 10:50 AM
#5
Originally posted by vbgladiator
I believe on Error goto ErrH: is a label
on error goto Errh is a statement.
On Error Goto is a statement and with goto you have to name the label. But the colon is only necassary to define the actual label.
-
Nov 5th, 2001, 10:52 AM
#6
Frenzied Member
So this is legal?
On error goto ErrHandler:
ErrHandler:
-
Nov 5th, 2001, 11:01 AM
#7
I ran a test before posting, because I wasn't sure if using a colon in the On Error would work, but it does. Run this in a test project
VB Code:
Private Sub Command1_Click()
On Error GoTo errh
Dim i As Integer
i = 1 / 0
errh:
MsgBox "Division by zero"
End Sub
You will get the Division by zero message box. Now run this
VB Code:
Private Sub Command1_Click()
On Error GoTo errh:
Dim i As Integer
i = 1 / 0
errh:
MsgBox "Division by zero"
End Sub
Once again, you will get the Division by zero message box.
-
Nov 5th, 2001, 11:04 AM
#8
Retired VBF Adm1nistrator
If you want to string multiple lines of code together into one long line of code you can use the full colon to put them together.
So I suppose you could probably stick a colon after anything and it would work the same
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Nov 5th, 2001, 11:05 AM
#9
Well actually Hack you'll get that message box even if you remove the division statement... You'll always need to exit the sub or function before the Label so the statements in the error handler is only executed if an error has occured.
-
Nov 5th, 2001, 11:07 AM
#10
Originally posted by plenderj
If you want to string multiple lines of code together into one long line of code you can use the full colon to put them together.
So I suppose you could probably stick a colon after anything and it would work the same
That's true. But the actual definition of the Label must be followed by a colon. That also proves that you can't use a keyword or a function name as a label.
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
|