global
Username:  
Password:
  > Home
> User Guide
v Reference
    > Introduction
    > CROFT
    > BEE Variables
    > BEE Syntax
    v BEE Commands
       > Variable Operations
       > Conditional
       > Loop
       v Module Calling
          o function
          o return
          o global
          o parent
          o include
          o exec
          o exit
       > Remote Calling
       > Authentication
       > Data Access
       > Socket
       > Special Functions
    > Database Operation
    > Content Management
    > Objects and Classes
    > Interface with others
    o Glossary
> Portal Object
> Development Guide


Shortcuts
sys Class
debug Class
Intrinsic Conversions
>> Reference >> BEE Commands >> Module Calling >> global <=  =>      <  1  >  
global – declare a variable to be from the global Context

BEE Script:   global [var];

 

BEE Tag:     <beeglobal [var]>

 

The "global" command is valid only within a function.  It declares that a variable is in the "global" Context, which means that the variable inherit the value set in the main script, and any changes to them inside the function will reflect onto the main script.

In another word, "global" variables are references to top level variables.

However, if the function calls another function, the "callee" function would not see the variables declared global in the "caller" function, unless the "callee" declares these variables "global" as well.

Example:

function welcome

{

      global sitename;

      var sitename = "Good Buy Shopping Mall";

      var who = "{sys%auth:username}";

      display "Welcome to {sitename}, {who}.<br> ";

}

 

var sitename = "a web site";

var who = "a user";

welcome;  // Welcome to Good Buy Shopping Mall, johnc.

display "{sitename} got {who}.<br> ";

// Good Buy Shopping Mail got a user.

 

Please note that while variable "sitename" has been set after the function call, changes to "who" inside the function did not show up in the display.

If the variable name (var) is missing, the whole Context (all variables in the global Context) will be declared global.  (Please use this carefully to avoid polluting the global environment.)

Previous Page       Next Page

Accsoft Computer Technology Pty Ltd     ABN: 98 065 617 549
PO Box 892, Epping NSW 1710         Level 1, Epping Office Park, 242 Beecroft Rd, Epping NSW 2121, Australia
Tel: Sydney - (02)98691668     National - 1300-881668         Fax: (02)98691866
© Copyright 2003 Accsoft Computer Technology Pty Ltd