Syntax
Sub SubName[(ArgumentList)]
Series of instructions
End Sub
Remarks
Defines a subroutine. A subroutine is a series of instructions that can be called repeatedly from the main subroutine and can make your macros shorter and easier to debug.
Argument | Explanation |
SubName | The name of the subroutine. |
ArgumentList | A list of arguments, separated by commas. You can then use these arguments in the subroutine. Values, string and numeric variables, and array variables are all valid arguments. |
Subroutines must appear outside the main subroutine — generally, you add subroutines after the End Sub instruction that ends the main subroutine. You can call a subroutine not only from the macro's main subroutine, but also from other subroutines and even other macros. For more information about using subroutines, including how to share variables and pass arguments between subroutines, see Chapter 4, "Advanced WordBasic," in Part 1, "Learning WordBasic."
Example
In this macro, the main subroutine calls the GoBeep subroutine, passing the number of times to beep through the variable numBeeps:
Sub MAIN numBeeps = 3 GoBeep(numBeeps) End Sub Sub GoBeep(count) For n = 1 To count Beep For t = 1 To 100 : Next 'Add time between beeps Next End Sub
If the GoBeep subroutine were in a macro named LibMacros, the call to the subroutine would be as follows:
Sub MAIN numBeeps = 3 LibMacros.GoBeep(numBeeps) End Sub
For more information about using subroutines in different macros, see Chapter 4, "Advanced WordBasic," in Part 1, "Learning WordBasic."
See Also
Call, Function¼End Function