goto statement in VBA
To answer Rick's question, the coding is about a UDF for a very
complicated
trading logic.
The main stream is already very long and it would be much cleaner and
easier
to read if using goto statement to jump to the sub trading logic.
I disagree with your conclusion. Much cleaner and easier to read would be
separate functions and/or subroutines (depending on if values needed to be
returned or not) that performed the code work and were called from your main
UDF. I'm thinking of a structure like this...
Function MyUDF(ArgList)
If Condition1 Then
MsgBox MyFunc(ArgList)
ElseIf Condition2 Then
Call SomeSub(ArgList)
ElseIf ...etc...
' ...etc...
Else
Call CatchAllSubroutine()
End If
' Other code, maybe dependent on results from above
' or containing other If-Then structures like above.
End Function
Function MyFunc(ParameterList)
' Code to do something and return a value
End Function
Sub SomeSub(ParameterList)
' Code to do something
End Sub
Sub CatchAllSubroutine()
' Code to handle whatever the above didn't
End Sub
The key to the above is to give full, meaningful names to your function and
subroutines; that way, your main UDF function will read clearly, like a
story, and what is going on will be totally clear. The functions and
subroutines you are calling can, in themselves, be structured with call outs
to other functions and subroutines as necessary. Doing it this way make the
code clear and you don't have to scroll through monstrously long listings of
code trying to find sections you are jumping around to. Each function or
subroutine will be listed in the right-hand drop-down list when
(General)(Declarations) is selected from the left-hand drop-down, so
navigating to the need subroutines or functions is quite easy. Also, as each
subroutine and function is bundled unto itself, future maintenance of its
code is easy to do. Anyway, this is probably a person-preference kind of
thing and, I am assuming, you are probably too far along in your current
coding to stop and restructure everything.
Rick
|