File Write Question

 


I'm trying to store the HIGH of the day in a folder, who's name, is the day of the month. ( i.e 20 )


PnvH=iHigh(NULL,1440,0); // 1 Day High



OHday = DoubleToStr(Day(),0);
FileOpen(OHday, FILE_CSV|FILE_WRITE, ';');

if(StrToDouble(OHday)>0)
{Alert("OHday is: ",OHday," PnvH is: ",PnvH);
FileWrite(OHday, PnvH);
FileClose(OHday);}


Creating a file folder who's name is the day of the month is not my problem. My problem is that no matter what I do, the file is empty. No number. No string.

Can anyone see or tell me what I'm missing? It must have something to do with converting Double to String, then, String to Double. If I don't convert "OHday" to StrToDouble in the "if"
statement, I get a "Type Mismatch" error.



Thanks!

 
You need to save the file handle returned by FileOpen() and pass that handle to FileWrite() and FileClose():
// ...
int handle = FileOpen(Day()+".csv", FILE_CSV|FILE_WRITE, ';');
// if...  
FileWrite(handle, DoubleToStr(PnvH,Digits));
FileClose(handle);
Day() will be automatically cast to string when passed to FileOpen() so there is no need to use DoubleToStr(). You do need to use DoubleToStr() to write PnvH so as the correct number of digits are printed to file.


Next time:
 
gordon wrote >>
You need to save the file handle returned by FileOpen() and pass that handle to FileWrite() and FileClose():
Day() will be automatically cast to string when passed to FileOpen(), there is no need to use DoubleToStr().


Next time:


Thanks, Gordon!

Worked like a charm!

Yellowbeard
Reason: