Procedure

Prev Next Home Home Table Of Contents Index

Procedure (name)

This word begins the definition of a procedure. A procedure is like a subroutine. Once the procedure is defined, all you have to do to call the procedure is use its name. The procedure definition is terminated by the command EndProc.


Example:
Procedure SelectFile BoxHeaderColor ForeColor BackColor BoxBorderColor Cyan Mag BoxInsideColor Yellow Mag InverseColor Yellow Red Return PickFile (FileType,4,5,17) EndProc

Whenever we use the word SelectFile in the menu, all the lines of the procedure SelectFile will execute.

Parameters can be passed to procedures. When a parameter is passed it is normally passed by value. This mean that a copy of the original is passed. Whatever you do to the copy doesn't affect the original value.


Example:
var A Procedure Square (X) X = X * X Writeln X EndProc

A = 6 Square (A) ;prints 36 Writeln A ;prints 6

In the above example Square (A) will write 36 but Writeln A will write 6. The reason is that Square passes a copy of A to X but the value of X is not returned to A. If you want the original A to be affected you would use the Loc command.


 A = 6
 Square (Loc A) ;prints 36
 Writeln A      ;prints 36

In this example we pass Loc A to the Square procedure. Thus, instead of X being set to 6, X is set to point to A. As a pointer, any operation performed on X is performed on A instead.

You can also return parameters from procedures using the Return command.


Example:
Procedure Cube (X) Return X * X * X EndProc

Writeln Cube(3) ;returns 27

In MarxMenu you can return any number of parameters as long as the calling procedure is expecting the same number of parameters.


Example:
Procedure CenterOfScreen Return (ScreenWidth / 2) (ScreenHeight / 2) EndProc

GotoXY(CenterOfScreen)

In the above example, GotoXY expects two parameters. CenterOfScreen returns two parameters so MarxMenu is happy with it.

You can pass many parameters and have them concatinated into a single string as the real parameter, much the way the parameters of the Writeln command work. Numbers passed are converted to strings.

When you define your procedure, if you have a single parameter whose name begins with a "$", MarxMenu will process all parameters passed as a single string.


Example:

Procedure WriteALine ($Line) FileWriteln(OutputFile,Line) EndProc

WriteALine DateString ' ' TimeString ' ' Temperature

In the above example, because WriteALine had the parameter $Line, it tells MarxMenu to concatinate all parameters passed to it into a single string and put it into the variable Line.

See Also: EndProc Return Loc ParamsToArray

Category: Misc

Prev Next Home Home Table Of Contents Index

Sponsors
Shopping
Forum
Forum
email
EMail
Index
Index
Home
Home