Variables

/*

Variables are place-holders for data units with variable values;

their value may change while program running.

Variables have “type”, depending value of holded data item.

Type of variables haven’t be declared or defined previously; type of a variable determined
“on the fly” ( automatically ) by system when a value assigned (even changed by type) to
this variable.

Variables have also “scope” (or visibility) and this is most important issue about variables.

This example demonstrate defining and usage of variables in basic manner.

*/

PROCEDURE Main()

LOCAL cExclusiveForPMain := "The variable 'cExclusiveForPMain' is 'LOCAL' in the " +;
 "Main() procedure; thus inaccessible outside of Main()"

 SETMODE( 60, 300 )
 CLS

 PUBLIC cPublicizedInMain := "The variable 'cPublicizedInMain' declared as 'PUBLIC' "+ ;
 " in the Main () procedure; thus is accessible everywhere"

 PRIVATE cPrivatizedInMain := "The variable 'cPrivatizedInMain' declared as 'PRIVATE' " +;
 " in the Main() procedure;" + ; 
 " thus is accessible everywhere"

 cUndeclaredInMain := "The variable 'cUndeclaredInMain' is UN-declared but assigned value " +;
 " in the Main() procedure;" + ; 
 " thus is PRIVATE (by default) and accessible everywhere"
 ?
 ? "In the procedure", PROCNAME(), ":" 
 ? cExclusiveForPMain
 ? cPublicizedInMain 
 ? cPrivatizedInMain
 ? cUndeclaredInMain 

 SubProcL1()

 ?
 ? "In the procedure", PROCNAME(), "(after returned SubProcL1() ) :" 
 ? "If attempted accessing to 'cExclusiveForPSubProcL1' here, a run time error " + ;
 " occurs: Variable doesn't exist" 
 ? cPublicizedInMain 
 ? cPrivatizedInMain 
 ? cUndeclaredInMain 
 ? "If attempted accessing to 'cExclusiveForPSubProcL1' here, a run time error " +; 
 "occurs: Variable doesn't exist"
? cPublicizedInTheSub

RETURN // Main()
PROCEDURE SubProcL1() // Sub procedure Level : 1
LOCAL cExclusiveForPSubProcL1 := "The variable 'cExclusiveForPSubProcL1' is 'LOCAL' " + ;
 "in the SubProcL1() procedure;" + ; 
 " thus inaccessible outside of SubProcL1()"

 ?
 ? "In the procedure", PROCNAME(), ":" 
 ? "If attempted accessing to 'cExclusiveForPMain' here, a run time error " + ;
 "occurs: Variable doesn't exist"
? cPublicizedInMain 
 ? cPrivatizedInMain 
 ? cUndeclaredInMain 
 ? cExclusiveForPSubProcL1

 cPublicizedInMain := "New value assigned in the SubProcL1() to PUBLIC " + ;
 "variable 'cPublicizedInMain' "
cPrivatizedInMain := "New value assigned in the SubProcL1() to PRIVATE variable " +; 
 "'cPrivatizedInMain' "
cUndeclaredInMain := "New value assigned in the SubProcL1() to UNDECLARED PRIVATE " + ;
 " variable 'cUndeclaredInMain' "
cExclusiveForPSubProcL1 := "New value assigned in the SubProcL1() to LOCAL variable " + ;
 "'cExclusiveForPSubProcL1' " 

 ? cPublicizedInMain 
 ? cPrivatizedInMain 
 ? cUndeclaredInMain 
 ? cExclusiveForPSubProcL1

 PUBLIC cPublicizedInTheSub := "The variable 'cPublicizedInTheSub' declared as 'PUBLIC' "+ ;
 " in the SubProcL1() procedure;" + ; 
 " thus accessible outside of SubProcL1()" + ;
 " (of course AFTER it is builded)"
 ? cPublicizedInTheSub 

RETURN // SubProcL1()

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.