WD: WordBasic: Using Line Numbers with Goto Statements

ID: Q97660

The information in this article applies to:

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$("Who is it?")
      10 if a$="" then GOTO 20
      15 Print A$
      16 Goto 25
      20 Print "You didn't enter anything"
      25
   End SUB

For more information about the Goto statement, see page 230 of "Using WordBasic."

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 "line 35"
      Goto 10
      30 MsgBox "line 30"
      450 Goto 35
      10 MsgBox "line 10"
   End SUB

REFERENCES

"Using WordBasic," by WexTech Systems and Microsoft, page 230

Additional query words: macro

Keywords          : winword word6 winword2 word7 word95 kbFont macword6 
Version           : WINDOWS:1.0,1.1,1.1a,2.0,2.0a,2.0a- CD,2.0b,2.0c,6.0,6.0a,6.0c,7.0,7.0a;MACINTOSH:6.0,6.0.1,6.0.1a
Platform          : MACINTOSH WINDOWS
Issue type        : kbhowto

Last Reviewed: December 9, 1998