WD: WordBasic: Using Line Numbers with Goto Statements

Last reviewed: February 2, 1998
Article ID: 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 95, versions 7.0, 7.0a
  • 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$("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 : kbfont winword winword2 word6 word7 word95 word97 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


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 2, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.