Copyright 2008 Shoptalk Systems
SUB subName [ zero or more comma delimited variable names ]
See also: CALL, FUNCTION
sub subName zero or more comma separated
parameter variable names
'code for the sub goes in here
This statement defines a subroutine. Zero or more parameters may be passed into the subroutine. A subroutine cannot contain another subroutine definition, nor a function definition.
The CALL statement is used to access the SUBROUTINE and to pass values into it. The values must be the same type as the SUB statement defines them to be. So the following example:
sub mySubName string$, number, otherString$
is called like this:
call mySubName "string value", 123, str$("321")
Subroutines can also be used as event handlers for widgets like buttons, links, etc. See BUTTON, LINK
The variable names inside a subroutine are scoped locally, meaning that the value of any variable inside a subroutine is different from the value of a variable of the same name outside the subroutine.
Global Variables and Devices
String, numeric and object variables declared with the GLOBAL statement are available in the main program and in subroutines and functions.
Arrays are global to a Run BASIC program, and visible inside a subroutine without needing to be passed in.
Special global status is given to certain default variables used for sizing, positioning, and coloring windows and controls. These include variables DefaultDir$, Platform$, UserInfo$, UrlKeys$, UserAddress$, ProjectsRoot$, ResourcesRoot$, Err$, Err, EventKey$, RowIndex. The value of these variables can be seen and modified in any subroutine/function.
Branch labels are locally scoped. Code inside a subroutine cannot see branch labels outside the subroutine, and code outside a subroutine cannot see branch labels inside any subroutine.
Ending a Subroutine:
The sub definition must end with the expression: end sub