Home |
Search |
Today's Posts |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
The more complicated the coding logic required the less you want to use goto
statements. As Rick states anything you can do with a goto statement you can do better with if then else and select case statements. Post what you have so far and some indication of what you need and we can steer you in the right direction. -- HTH... Jim Thomlinson "Laurie" wrote: First thanks both Rick and Tom for your confirmation, and Tom for your demonstration!!! 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. It's comforting to know under the label line, there can be as many statements as necessary. I guess my next question would be how to define the end of the block of statements under the label line? For the trading logic instance as demonstrated below, ideally, I would like to retrieve the results from executing the statements under the label line to be used in the statements following the "goto Label" line. Is this the case by the code logic? Also, after the block of statements, which are supposed to be under the Label line, I would like to have another block of statements, like Select Case statements, which are not belonging to the block of statements under the Label line. Can this be done? Can the VBA program automatically know how to handle the above two situations or should I do something to help the VBA program recognize the above two situations? The UDF program flow is as below Function Name1(...) ...(block of statements)... if ... then goto Label ... (more statements)... end if Label: ... (block of statements)... Select Case Var1 .... End Select End Function "Rick Rothstein (MVP - VB)" wrote: There is no practical limit for how many statements can be in the block following the GoTo statement. With that said, you will do yourself a big favor if you learn not to use the GoTo statement (it makes code much harder to read, especially several months from now when you come back to edit your code). With the exception of On Error GoTo error handler, there is almost no situation where GoTo is the correct solution. You can usually almost always use an If-Then-Else or Select-Case block structure instead. Why don't you outline what you are trying to code using GoTo and let's see if someone here can show you a better way to code it. Rick "Laurie" wrote in message ... Hi everyone who may help, I am trying to use the goto statement in VBA in Excel. From the Help, goto statement can jump to a label line. I am wondering that, under the label line, which the goto statement jumps to, how many statements are allowed? In the help, only one line of statement is under the label line. Can there be a block of statements under the label line? Any help would be really appreciated. Thanks a lot, Laurie |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
? IF and GOTO ? | Excel Worksheet Functions | |||
Goto | Excel Programming | |||
Goto statement in an IF function | Excel Worksheet Functions | |||
On Error Goto doesn't goto | Excel Programming | |||
On Error Goto doesn't goto | Excel Programming |