Write a string array into a CSV file but only the word "FALSE" as result inside file.

 

Hello everyone!

I'm trying to make my EA to get data from online CSV file and write down to a local file, but it worked wrongly. The destination file is only saved with the word "FALSE" inside as data, even i tried some other function to write data.

So, please! anyone can help me to show my mistakes in the codes below: (result file is attached below)

Thank you all!

void OnStart()
  {
      char data[];
      char result[];
      string result_headers;
      int res = WebRequest("GET", "http://fbgfx.pro/fbgfx.pro/fbgfxcopier/Orders.csv", "", 10, data, result, result_headers);
      if(res==-1)
         {
         Print("Error in WebRequest. Error code  =",GetLastError());
         MessageBox("Add the address '' in the list of allowed URLs on tab 'Expert Advisors'","Error",MB_ICONINFORMATION);
         }
      else
      {
         //--- Load successfully
         PrintFormat("The file has been successfully loaded, File size =%d bytes.",ArraySize(result));
         string csv = CharArrayToString(result);
//         string rows[];
//         StringSplit(csv, '\n', rows);
         //--- Save the data to a file
         int handle=FileOpen("Orders.csv",FILE_READ|FILE_WRITE|FILE_CSV|FILE_ANSI);
      //--- Checking errors
         if(handle!=INVALID_HANDLE)
         {
            Alert(csv);
            //--- Save the contents of the result[] array to a file
            FileWriteString(handle,csv+"\r\n");
            //--- Close the file
            FileClose(handle);
         }
         else Print("Error in FileOpen. Error code=",GetLastError());
      }
   
  }
Files:
Orders.csv  1 kb
 
Quang Tran:

Hello everyone!

I'm trying to make my EA to get data from online CSV file and write down to a local file, but it worked wrongly. The destination file is only saved with the word "FALSE" inside as data, even i tried some other function to write data.

So, please! anyone can help me to show my mistakes in the codes below: (result file is attached below)

Thank you all!

Try this code.

void OnStart()
{
//---
   string cookie = NULL, headers;
   char post[], result[];
   int res;
   int timeout = 5000;
   string URL = "http://fbgfx.pro/fbgfx.pro/fbgfxcopier/Orders.csv";

   ResetLastError();
   res = WebRequest("GET", URL, cookie, NULL, 500, post, 0, result, headers);

   if(res == -1)
   {
      Print("Error in WebRequest. Error code  =", GetLastError());
      MessageBox("Add the address '" + URL + "' in the list of allowed URLs on tab 'Expert Advisors'", "Error", MB_ICONINFORMATION);
   }
   else
   {
      PrintFormat("The file has been successfully loaded, File size =%d bytes.", ArraySize(result));
      string csv = CharArrayToString(result);
      //--- Save the data to a file
      int handle = FileOpen("Orders.csv", FILE_READ | FILE_WRITE | FILE_TXT | FILE_ANSI);
      //--- Checking errors
      if(handle != INVALID_HANDLE)
      {
         FileWriteString(handle, csv);
         //--- Close the file
         FileClose(handle);
      }
      else
         Print("Error in FileOpen. Error code=", GetLastError());
   }
}
 
Nagisa Unada:

Try this code.

Thank everyone!

It worked

Reason: