LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default goto statement in VBA

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
? IF and GOTO ? Karen D Excel Worksheet Functions 2 September 1st 09 07:57 PM
Goto alvin Kuiper Excel Programming 5 August 6th 07 12:46 PM
Goto statement in an IF function =\ Excel Worksheet Functions 2 August 11th 05 06:21 PM
On Error Goto doesn't goto Paul Excel Programming 1 October 15th 04 03:51 PM
On Error Goto doesn't goto Paul Excel Programming 0 October 15th 04 03:05 PM


All times are GMT +1. The time now is 03:49 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"