Passing Parameters to Procedures

Prev Next Home Home Table Of Contents Index

PASSING PARAMETERS TO PROCEDURES

Procedures can accept parameters by declaring variable names on the same line as the name of the procedure.

Procedures can return variables by using the Return command. Return exits the procedure returning the parameters on the same line as the Return statement.


Example:
Procedure Factorial (X) var Y Z Y = 1 Z = 1 while Y <= X Z = Y * Z Y = Y + 1 endwhile Writeln X ' factorial is ' Z EndProc

In this example, if you were to use Factorial (5) you would get:


 5 factorial is 120

Example:

Procedure AskYesNo (Question) var YesNo DrawBox (34 - (Length(Question) / 2)) 21 Length(Question) + 14 3 TextColor LCyan Blue UseArrows Off Write ' ',Question,' (Y/N) ' YesNo = UpperCase(ReadKey) YesNo = YesNo = 'Y' if YesNo Write 'Yes' else Write 'No' endif Wait 50 EraseTopWindow Return (YesNo) EndProc

if AskYesNo 'Do you want to continue? ' then Continue

In this example, MarxMenu draws a box and asks a question and waits for a "Yes" or "No" answer.

Arrays can be passed as parameters. Parameters are passed by value not by reference. This means that any changes to the passed parameter do not affect the original value.

You can copy an array by assigning it equal to another array.


Example:
Array1 = Array2

This creates Array1 with a copy of all the elements of Array2. The previous contents of Array1 are overwritten.

Prev Next Home Home Table Of Contents Index

Sponsors
Shopping
Forum
Forum
email
EMail
Index
Index
Home
Home