Re: On Local Error Goto Somewhere
- From: "Lorin" <lorinm@xxxxxxxxxxx>
- Date: Tue, 20 Jun 2006 22:45:17 -0700
You have just the same problem with a nested set of statements that contain
an EXIT DO or EXIT FOR.
There you cannot even see at the statement after the NEXT or LOOP that
anything jumps to that point.
Talk about blind.
And ... at the EXIT DO or EXIT FOR it can be difficult to see where it is
going if there is no label to show you the destination.
Remember I am talking about nested statements, not just some simple FOR NEXT
loop etc.
And no, I do not like to write a bunch of nested subroutines to eat up
processor time pushing and popping the stack, thank you very much!
You must write very very simple code not to understand this.
Thank goodness we do not have to deal with
{
}
GOTOs rule (used wisely). And so do GOSUBS.
"R. MacDonald" <scitec@xxxxxxxxxxxxxxx> wrote in message
news:449660dd$0$51886$dbd43001@xxxxxxxxxxxxxxxxxx
Hello, Lorin,
IMO the GoTo statement has never been "THE" problem. The problem is the
"ComeFrom" statement -- i.e. the label. When I am looking at a GoTo, I
know immediately where the next statement is. When I see a label, I don't
have a clue how I got there. You have said this yourself in your comment
' label are cheap, and I can search to
find the source of this destination
The point is, that you have to search, and searching (my opinion) is not
cheap.
Cheers,
Randy
Lorin wrote:
This brings up the discussion of GOTO since On Error GOTO is a GOTO.
This is the VB6 code I use on occassion if pressed
Public Function MySub(sMyFile as String) as String()
ON ERROR GOTO MySubErr Dim lFNbr as long
Dims sBuffer as String
Dim sArgs() as String
Dim iX as Integer
sBuffer = String$(50," ")
' some code
Do
100 Open sMyFile For Binary As lFnbr
200 Get lFNbr,, sBuffer ' what happens if there are not that many
characters in the file?
If Split(sBuffer,",")(0) = "VALID" Then ' just making a point
sArgs=Split(sBuffer, ",") ' now get all
For iX = 0 to UBound(sArgs)
if sArg(iX) = "OOPS" then Exit Do ' a convieient
was to escape using this GOTO
' Note it skips
out of the FOR as well as the DO
if sArg(iX) = "GOSH" Then GoTo FlyingLeap ' another type
of GOTO
' Now which is easier to follow?
' Can your eye find the label first or the end of the Loop?
' Labels are automatically left justified.
' what if this was in a complex multilayered nested bit of
code?
Next iX
MySub = sArgs
EndIf
Loop While 0 ' solely the target of a GOTO, can you spot it?
' mixed message, I know, but what the heck.
FlyingLeap: ' label are cheap, and I can search to find the source of
this destination
' some additional code goes here to do something very usefull
MySubExit:
Close lFnbr ' it always closes due to controlled exiting
' cleanup even from errors
Exit Sub
MySubErr:
Debug.Print Err.Description
Select case ERL
Case 100
' do something here in code
' if there is a possibility on an error at this point then call a
subroutine with its own error handling to do the work and catch an error
Case 200
' do something else here in code
Case Else
' handle other errors here
End Select
' all errors resume to MySubExit
Resume MySubExit
End Sub ' MySub <---- do you know why I always do this?
I know, all you purists go HISSSS and BOOOO.
THis is not Spaghetti, just clear and responsible coding.
Any discussion????
Stirring the pot.
"Lorin" wrote:
Please compare and contrast this with
On Error Goto Somewhere
Big thnks!
.
- References:
- RE: On Local Error Goto Somewhere
- From: Lorin
- Re: On Local Error Goto Somewhere
- From: R. MacDonald
- RE: On Local Error Goto Somewhere
- Prev by Date: Re: Compile Missfire?
- Next by Date: Re: GOTOs to the People - Discussion please!
- Previous by thread: Re: On Local Error Goto Somewhere
- Next by thread: Data to CDR
- Index(es):
Relevant Pages
|