Passing array name to function

 

Hello, I'm writing a function that utilizes FileWriteArray to simplify the body of my code as my program will need to utitlize this function serveral times.

I am getting the errors:

"bidArray - parameter conversion not allowed"

"bidArray - invalid array access"

The error is very likely related to the array argument in FileWriteArray and it may be related to the datatype as I'm trying to pass it as a string.

Is there a way to simply pass the name of the array I'm trying to write to file to a function?

Thank you

double bidArray[];
int count = 0;

void OnTick()
{
        ArrayResize(countArray, count+1);
        bidArray[count] = Bid;
        count++;
        
        if (some arbitrary condition)
        {
                writeFile(bid, bidArray);
        }
        
}

//+------------------------------------------------------------------+

void writeFile(string name, string arrayName)
{
   filename = name+".bin";
   file_handle=FileOpen(filename,FILE_WRITE|FILE_BIN); 
   if(file_handle!=INVALID_HANDLE) 
   { 
      FileWriteArray(file_handle, arrayName, 0, WHOLE_ARRAY); 
      FileClose(file_handle); 
   }
   else
   {
      Print(GetLastError());
   }
}
 
Hoi Cheng:

Hello, I'm writing a function that utilizes FileWriteArray to simplify the body of my code as my program will need to utitlize this function serveral times.

I am getting the errors:

"bidArray - parameter conversion not allowed"

"bidArray - invalid array access"

The error is very likely related to the array argument in FileWriteArray and it may be related to the datatype as I'm trying to pass it as a string.

Is there a way to simply pass the name of the array I'm trying to write to file to a function?

Thank you

1.you need to set the arrayName as => arrayName[] to indicate it expects an array 

2.you need to place a & before the name to indicate its a reference &arrayName[]

void writeFile(string name, string &arrayName[])
 
void writeFile(string name, string &arrayName[])

The array passed is a double.

 
William Roeder:

The array passed is a double.

3.you need to pass the correct array type