//+------------------------------------------------------------------+
//| Test.mq5 |
//| Copyright 2021, MetaQuotes Ltd. |
//|
https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Ltd."
#property link "
https://www.mql5.com"
#property version "1.00"
//-------------------------------------------------------------------
int filehandle;
int str_size;
int TP_Buy, SL_Buy;
int TP_Sell, SL_Sell;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
string terminal_data_path=TerminalInfoString(TERMINAL_DATA_PATH);
string filename=terminal_data_path+"\\MQL5\\Files\\"+"csv.csv";
//filehandle=FileOpen(filename,FILE_READ|FILE_CSV);
ResetLastError();
filehandle=FileOpen("csv.csv",FILE_READ|FILE_CSV);
//--------------------------
if(filehandle<0)
{
Print("Failed to open the file by the absolute path ");
Print("Error code ",GetLastError());
}
//--- correct way of working in the "file sandbox"
if(filehandle!=INVALID_HANDLE)
{
while(!FileIsEnding(filehandle))
{
TP_Buy = (int)StringToInteger(FileReadString(filehandle));
SL_Buy = (int)StringToInteger(FileReadString(filehandle));
TP_Sell = (int)StringToInteger(FileReadString(filehandle));
SL_Sell = (int)StringToInteger(FileReadString(filehandle));
Print("TP : ",TP_Buy," sl : ",SL_Buy);
}
FileClose(filehandle);
}
//--------------------------
//Comment(filehandle," tp b : ",TP_Buy," sl b : ",SL_Buy);
}
//+------------------------------------------------------------------+
ช่วยดูโค๊ดให้หน่อยครับ ผมลองดึงค่า ซึ่งมันมีไฟล์ csv.csv อยู่แล้ว แต่ดึงค่าออกมาอย่างไรก็ได้ 0 อยู่ดีครับ