Microsoft KB Archive/97660

{|
 * width="100%"|

WD: WordBasic: Using Line Numbers with Goto Statements

 * }

Q97660

-

The information in this article applies to:


 * Microsoft Word for Windows, versions 2.0, 2.0a, 2.0a-CD, 2.0b, 2.0c, 6.0, 6.0a, 6.0c
 * Microsoft Word for Windows NT, version 6.0
 * Microsoft Word for Windows, versions 7.0, 7.0a
 * Microsoft Word for the Macintosh, versions 6.0, 6.0.1

-

SUMMARY
To use the WordBasic Goto statement in your Word macro to branch to a specific line number in the macro, your macro must contain a line number at the beginning of the line.

For example, to use the Goto 20 statement, you should number the lines in your macro as shown in the following sample macro:

  Sub Main 5 A$=inputbox$(&quot;Who is it?&quot;) 10 if a$=&quot;&quot; then GOTO 20 15 Print A$     16 Goto 25 20 Print &quot;You didn't enter anything&quot; 25  End SUB For more information about the Goto statement, see page 230 of &quot;Using WordBasic.&quot;

MORE INFORMATION
In the Word for Windows WordBasic macro language, it is not customary to number the lines of your macro, but it is acceptable to do so. Do not type a colon after the number. For example, the following line does not contain a valid line number, while the macro in the previous section does contain valid line numbers:

  15: Print A$ Line numbers do not need to be continuous, and you can number the lines in ascending as well as descending order, as shown in the sample macro below. It is a programming custom to number lines in ascending order.

Sample Macro, Numbered Noncontinuously in Descending Order
  Sub MAIN 100 Goto 30 35 MsgBox &quot;line 35&quot; Goto 10 30 MsgBox &quot;line 30&quot; 450 Goto 35 10 MsgBox &quot;line 10&quot; End SUB