UDFs_02 : Calling by reference

/*

UDFs_02 : Calling by reference

In the previous example “cCurrent” was an “argument” ( or actual parameter ), in caller side. In called (invoked / recevied ) side “cTime” is a parameter ( or “formal” parameter).

Though two variables has same value (at the beginning of called function), nothing changed in these definitions, though if two variables has the same name.

In the previous example, “cCurrent” passed by value by caller and “cTime” is a “local” variable as a (“formal”) parameter. So, after terminated the “AmPm” function, “cTime” too erased from memory and became inaccessible.

There is one another method: passing by reference. In this method, caller routine passes (sent) the argument by its reference, not value. In this case called routin uses this formal parameter by its reference, can change  its value and after termination of called routine, argument left alive for caller.

For passing an argument by reference only requirement is adding a “@” sign at the beginning of variable name: AmPm( @cCurrent ), instead of AmPm( cCurrent ).

In this case we haven’t need a return value by called routine, and so called routine haven’t being a FUNCTION.

For more information refer here:

*/

PROCEDURE Main()
cCurrent := "01:43" 

 AmPm( @cCurrent )

 ? cCurrent

 WAIT

RETURN // Main()
*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.
PROCEDURE AmPm( cTime )
IF VAL( cTime ) < 12
 cTime += " am"
 ELSEIF VAL( cTime ) = 12
 cTime += " pm"
 ELSE 
 cTime += STR( VAL( cTime ) - 12, 2 ) +;
 SUBSTR( cTime, 3 ) + " pm"
 ENDIF

RETURN // AmPm()
*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.