Home About Contact
ForexForums.org




Reply
Old 10-23-2006, 02:37 PM   #1 (permalink)
Administrator
 
kokas's Avatar
 
Join Date: Sep 2006
Location: Portugal
Posts: 507
Global Variables functions

Global Variables functions
bool GlobalVariableCheck(
string name)

Return logical true if global variable exists, otherwise returns false. To get the detailed error information, call GetLastError() function.
Parameters
name
-
Global variable name.

Sample
// check variable before use
if(!GlobalVariableCheck("g1"))
GlobalVariableSet("g1",1);

bool GlobalVariableDel(
string name)

Deletes global variable. If the function succeeds, the return value will be true. If the function fails, the return value is false. To get the detailed error information, call GetLastError().
Parameters
name
-
Global variable name.

Sample
// deleting global variable with name "gvar_1"
GlobalVariableDel("gvar_1");

double GlobalVariableGet(
string name)

Returns global variable value. To check function failure, check error information by calling GetLastError().
Parameters
name
-
Global variable name.

Sample
double v1=GlobalVariableGet("g1");
//---- check function call result
if(GetLastError()!=0) return(false);
//---- continue processing

datetime GlobalVariableSet(
string name, double value)

Sets global variable value. If it does not exist, the system creates a new variable. If the function succeeds, the return value is last access time. If the function fails, the return value is 0. To get the detailed error information, call GetLastError().
Parameters
name
-
Global variable name.
value
-
Numeric value to set.

Sample
//---- try to set new value
if(GlobalVariableSet("BarsTotal",Bars)==0)
return(false);
//---- continue processing

bool GlobalVariableSetOnCondition(
string name, double value, double check_value)

Sets the new value of the global variable if the current value equals to the third parameter check_value. If there is no variable at all, the function will return false and set the value of ERR_GLOBAL_VARIABLE_NOT_FOUND constant to LastError. When successfully executed, the function returns true, otherwise it does false. To receive the information about the error, call GetLastError() function.
The function can be used as a semaphore for the access to common resources.

Parameters
name
-
Global variable name.
value
-
Numeric value to set.
check_value
-
Value to compare with the current global variable value.

Sample
int init()
{
//---- create global variable
GlobalVariableSet("DATAFILE_SEM",0);
//...
}

int start()
{
//---- try to lock common resource
while(!IsStopped())
{
//---- locking
if(GlobalVariableSetOnCondition("DATAFILE_SEM",1,0 )==true) break;
//---- may be variable deleted?
if(GetLastError()==ERR_GLOBAL_VARIABLE_NOT_FOUND) return(0);
//---- sleeping
Sleep(500);
}
//---- resource locked
// ... do some work
//---- unlock resource
GlobalVariableSet("DATAFILE_SEM",0);
}

void GlobalVariablesDeleteAll(
)

Deletes all global variables. This function never fails.
Sample
GlobalVariablesDeleteAll();

Attached Files
File Type: doc Global Variables functions.doc (47.0 KB, 8 views)
kokas is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply

Bookmarks



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Sedo - Buy and Sell Domain Names and Websites project info: forexforums.org Statistics for project forexforums.org etracker® web controlling instead of log file analysis

All times are GMT. The time now is 12:36 PM.
Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.