Local variable: Difference between revisions
(Created page with "In BR, all variables are global variables, even those used in User Defined Functions. In other words, if your program sets x=4, and your library function includes the line...") |
No edit summary |
||
Line 21: | Line 21: | ||
Back in the program, X will contain the value of 8 or NewNum. | Back in the program, X will contain the value of 8 or NewNum. | ||
[[Category: | [[Category:Variable]] |
Latest revision as of 17:38, 29 June 2015
In BR, all variables are global variables, even those used in User Defined Functions. In other words, if your program sets x=4, and your library function includes the line x=7, then if your original program uses x again, it will use the value 7.
However, there is a way to get around this: make X a optional parameter in your user defined function, and do not bring it in.
Program contains:
let X=4
Library function definition includes X after the semi-colon:
def fnModifyRec(FileNumber,SubscriptToRead,RecordNumber;X)
Program calls the fnModifyRec function, without bringing in the variable X:
fnModifyRec(PickFile,PickSub,PickRec)
Back in the program, X is still 4.
In contrast, the following call would make X work like a global variable and alter the value of X in the program, since it uses the optional variable:
fnModifyRec(PickFile,PickSub,PickRec;8)
or
fnModifyRec(PickFile,PickSub,PickRec;NewNum)
Back in the program, X will contain the value of 8 or NewNum.