MY code have problom?

 
 
      double a=4.0;
      double    b=4.5;
      if(a>b)  Alert("ok1");
      if(a<b)  Alert("ok2");
      if(a==b) Alert("ok3");
 double a=4.0;
      int b=4;
      if(a>b)  Alert("ok1");
      if(a<b)  Alert("ok2");
      if(a==b) Alert("ok3");
int MAINX= FileOpen("MAIN2222.TXT", FILE_COMMON|FILE_CSV|FILE_READ|FILE_WRITE);
           FileWrite(MAINX,4);  
           FileSeek(MAINX, 0, SEEK_SET);
           FileClose(MAINX);
   
           int MAINX= FileOpen("MAIN2222.TXT", FILE_COMMON|FILE_CSV|FILE_READ|FILE_WRITE);
           FileSeek(MAINX,0,SEEK_SET);
           double a=FileReadNumber(MAINX);  //这里的方向只代表了美元的多头方向
           FileClose(MAINX);
      
           int b=4;
        
      
      if(a>b)  Alert("ok1");
      if(a<b) Alert("ok2");
      if(a==b) Alert("ok3"); 
Look last Code ,why the run ruzult is  ok2    not  ok3?
 
It is ok3.
 

It is  "ok2"!!  "a" has a value of 0.00, because "4" is not written into the file.  FileOpen( ... FILE_WRITE) seems not to work with CSV files! You can try with binary files and a unifying function,  for example:

long x = 4;

 int MAINX = FileOpen( ...., | FILE_BIN); // instead of FILE_CSV

FileWriteLong( MAINX, x);

 (...)

int MAINX1 = FileOpen( ..., | FILE_BIN);

long a =  FileReadLong( MAINX1);

( ...)

int b = 4;  etc...

Then you should become "ok3".


You can use also a text file , with  " ...| FILE_TXT" and strings.

For example,

string x = 4";

int MAINX = FileOpen( ...., | FILE_TXT); // instead of FILE_CSV

FileWriteString( MAINX, x);

(...)

int MAINX1 = FileOpen( ..., | FILE_TXT);

string s =  FileReadString( MAINX1);

( ...)

int  a  = (int) StringToInteger( s);

int b = 4;

(...)

You should also  become "ok3".

 

Try:

if(NormalizeDouble(a,0)==NormalizeDouble(b,0)) Alert("ok3");  

 
JMRodMartins:

It is  "ok2"!!  "a" has a value of 0.00, because "4" is not written into the file.  FileOpen( ... FILE_WRITE) seems not to work with CSV files! You can try with binary files and a unifying function,  for example:



Did you try it? I have tried it and it does write txt file and the result is "ok3". The only compile error is it declares "int" twice on MAINX.

 
belido:

Did you try it? I have tried it and it does write txt file and the result is "ok3". The only compile error is it declares "int" twice on MAINX.

Now it seems it's ok also with CSV files! Now it's "ok3". Very good!