バイナリファイルの現在位置から単精度浮動小数点数(float)を読み取ります。
float FileReadFloat(
int file_handle
);
|
パラメーター
file_handle
[入力] FileOpen()によって返されるファイル記述子。
戻り値
注意
例(FileWriteFloat()関数の例を実行した後に取得したファイルがここで使用されます)
//+——————————————————————+
//| Demo_FileReadFloat.mq4 |
//| Copyright 2014, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+——————————————————————+
#property copyright “Copyright 2014, MetaQuotes Software Corp.”
#property link “https://www.mql5.com”
#property version “1.00”
#property strict
//— parameters for data reading
input string InpFileName=“Close.bin”; // file name
input string InpDirectoryName=“Data”; // directory name
//— global variables
int size=0;
double close_buff[];
datetime time_buff[];
//+——————————————————————+
//| Script program start function |
//+——————————————————————+
void OnStart()
{
//— open the file
ResetLastError();
int file_handle=FileOpen(InpDirectoryName+“//”+InpFileName,FILE_READ|FILE_BIN);
if(file_handle!=INVALID_HANDLE)
{
PrintFormat(“%s file is available for reading”,InpFileName);
PrintFormat(“File path: %s\\Files\\”,TerminalInfoString(TERMINAL_DATA_PATH));
//— read data from the file
while(!FileIsEnding(file_handle))
{
size++;
//— check size
if(size>ArraySize(time_buff)) ArrayResize(time_buff,size,100);
if(size>ArraySize(close_buff)) ArrayResize(close_buff,size,100);
//— read time and price values
time_buff[size-1]=(datetime)FileReadDouble(file_handle);
close_buff[size-1]=(double)FileReadFloat(file_handle);
}
//— close the file
FileClose(file_handle);
PrintFormat(“Data is read, %s file is closed”,InpFileName);
//— check arrays
if(ArraySize(time_buff)==ArraySize(close_buff))
{
//— print data
PrintFormat(“Read data:%d”,ArraySize(time_buff));
for(int i=0; i<ArraySize(time_buff); i++) PrintFormat(“%d, time=%s, close price=%s”,i,TimeToString(time_buff[i]),DoubleToString(close_buff[i],_Digits));
}
else
Print(“Error in data.”);
}
else
{
PrintFormat(“Failed to open %s file, Error code = %d”,InpFileName,GetLastError());
return;
}
}
|
0 people found this article useful
0 people found this article useful