Global Variable

how to make a global variable ?

use [name_global]

Global variables are defined as follows in a Scriptcase application:

sc_set_global <–Scriptcase macro to define a Global variables

Example:
sc_set_global($oProjectAppName); // Project Application Name to Execute

The above is how the variable is defined in an Application

Next initialize the variable:

[oProjectAppName] = “” <-- This initializes the variable using square brackets “[” and “]”

Lastly, in the Application WHERE the variable is defined be sure to set its type to “Out”. In all other applications that use the variable the type should be defaulted to “In”. This tells Scriptcase that you have a Global variable being passed.

When you want to refer to the Global variable in a function use a local variable first to equal the Global variable. You cannot pass the Global variable into a function directly.

I am a bit unsure of this too. I have a PHP Method that has these 2 lines in them
$minutes_used_today = 10;
sc_set_global($minutes_used_today);
[minutes_used_today] = $minutes_used_today;

I have set the Global Variables to be “Out” and clicked session, GET and POST .Do I need all three?
Nonethless if I access the variable elsewhere using [minutes_used_today] it does not show anything

No you do not. Uncheck both GET and POST. Just leave session checked. This is what I do.

Also. when you want to pass a GLOBAL variable to a function first create a local variable and then pass that local variable.

$var_local = [var_global];

phpfunc($var_local) <-- passed local variable is allowed

The function you are creating in either PHP or Javascript. In either case you need to follow the guidelines for passing variables in PHP/Javascript).

The same is true to returning a variable from PHP/Javascript back to Scriptcase

[var_global] = $var_local;

$var_local get the return value from the function and then passes it back to Scriptcase.

1 Like

OK, still does not work. If I put this (after having run the app with the code above )
echo “minutes_used_today:” . [minutes_used_today] . “<BR>”;
On another app it has no value. The only ones that work for me are ones set in appLogin. In fact the above code works in the appLogin page but not anywhere else.

The line you typed in your last post:

echo “minutes_used_today:” . [minutes_used_today] . “<BR>”;

Make sure that the <BR> is in lower case “<br>”.

You are a f***ing genious!