Re: GOTOs to the People - Discussion please!
- From: "Ralph" <nt_consulting64@xxxxxxxxx>
- Date: Sun, 18 Jun 2006 23:44:46 -0500
"Lorin" <Lorin@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:A9570BA0-E676-4268-83E6-9C5E4E0A6A7D@xxxxxxxxxxxxxxxx
was
On Error GoTo Geneva ' for a convention
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
to escape using this GOTOout
' Note it skips
of the FOR as well as the DOcode?
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
Next iXthis
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
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.
VB6's comprehensive frame-based exception handling for guarding code blocks
was rather advanced for its time. (cf. VC++ at the time had at least 3
different incompatible methods). Utilizing exception handling is absolutely
essential in developing a professional application, since in a compiled app
an unhandled error is FATAL and will likely cause the entire app to crash.
Error handling was implemented using Labels opposed to adding new keywords
or complex contructs to the language. When utilized correctly it can be
quite eloquent. While it may use the label mechanism (and syntax) don't
confuse it with the archiaic use of Gotos.
The only 'purity' in my hiss and boo is to note your code is *pure* classic
spaghetti code the result of muddled thinking.
-ralph
.
- References:
- GOTOs to the People - Discussion please!
- From: Lorin
- GOTOs to the People - Discussion please!
- Prev by Date: Re: Firing blanks here! (IGNORE - Wrong NG. Sorry!)
- Next by Date: Re: Firing blanks here! (IGNORE - Wrong NG. Sorry!)
- Previous by thread: Re: GOTOs to the People - Discussion please!
- Next by thread: RE: GOTOs to the People - Discussion please!
- Index(es):
Relevant Pages
|