How to get account info as a variable

 

Trying to do a few things here. One, How to get account info and store as a double global variable?

int AccountNumber();
string AccountName();

then how to use that variable to name a file such as:

int handle;
datetime orderOpen=OrderOpenTime();
handle=FileOpen("filename", FILE_CSV|FILE_WRITE, ';');
if(handle>0)
{
FileWrite(handle, Close[0], Open[0], High[0], Low[0], TimeToStr(orderOpen));
FileClose(handle);
}

"filename" seems it cannot be a variable. so how do we name a new file to write to based on a variable?

 
eliteeservices:

"filename" seems it cannot be a variable. so how do we name a new file to write to based on a variable?

Yes, the filename parameter to FileOpen() can be a variable.


There are two obvious possible problems you may be having. One is that you're trying to use FileOpen() to write to a file outside of experts\files - this isn't allowed. The second is that you're building the file name from the account name, and the account name includes characters which aren't allowed in file names, such as : or /

 
eliteeservices:

One, How to get account info and store as a double global variable?

You can obviously store the integer account number in a global variable (a double, as you say), but you can't store the string account name.


The best workaround partly depends on why you want to put a value into a global variable which is static and re-obtainable anyway (unless the user logs in to a new account). One option is to use a file on disk rather than a global variable. If you only need to compare the current account name against some previous record, then you could calculate some sort of numeric hash of account names, put that number in a global variable, and compare the hash of the current name against the pre-recorded one.