Download MetaTrader 5

Error when "StringSubstr" used, pls help

To add comments, please log in or register
sathyaicm
17
sathyaicm  

Hi,

I'm porting my mq4 program to mq5 and I face compilation issues, not sure what variable expected here as I'm already passing str variable for StringSubst. 


   const string str=NewsArr[0][nomf];

   string time=StringConcatenate(StringSubstr (str,0,4),".",StringSubstr(str,5,2),".",StringSubstr(str,8,2)," ",StringSubstr(str,11,2),":",StringSubstr(str,14,4));


Error:

'StringSubstr' - variable expected   


Pls help

whroeder1
15040
whroeder1  
sathyaicm: string time=StringConcatenate..
Is this an indicator with code in OnCalculate where you have a parameter named time?
sathyaicm
17
sathyaicm  

whroeder1: Thanks for your reply! No this is not for indicator, time is just a string array.

I'd initialized as below,

int time1[150],time2[150],time3[150];
string time[150],timeread[150],timeap[150];
string hour[150],hour1[150],hour2[150];

Mladen Rakic
57567
Mladen Rakic  
sathyaicm:

Hi,

I'm porting my mq4 program to mq5 and I face compilation issues, not sure what variable expected here as I'm already passing str variable for StringSubst. 


   const string str=NewsArr[0][nomf];

   string time=StringConcatenate(StringSubstr (str,0,4),".",StringSubstr(str,5,2),".",StringSubstr(str,8,2)," ",StringSubstr(str,11,2),":",StringSubstr(str,14,4));


Error:

'StringSubstr' - variable expected   


Pls help

It does not work when you use it within the StringConcatenate() function

Use it like this instead

   string time=StringSubstr(str,0,4)+"."+StringSubstr(str,5,2)+"."+StringSubstr(str,8,2)+" "+StringSubstr(str,11,2)+":"+StringSubstr(str,14,4);  
Alain Verleyen
Moderator
31595
Alain Verleyen  
Mladen Rakic:

It does not work when you use it within the StringConcatenate() function

Use it like this instead

   string time=StringSubstr(str,0,4)+"."+StringSubstr(str,5,2)+"."+StringSubstr(str,8,2)+" "+StringSubstr(str,11,2)+":"+StringSubstr(str,14,4);  

Yes it works with StringConcatenate(), but the mql5 version of this function is not the same as mql4.

   string time;
   StringConcatenate(time,StringSubstr (str,0,4),".",StringSubstr(str,5,2),".",StringSubstr(str,8,2)," ",StringSubstr(str,11,2),":",StringSubstr(str,14,4));  
Mladen Rakic
57567
Mladen Rakic  
Alain Verleyen:

Yes it works with StringConcatenate(), but the mql5 version of this function is not the same as mql4.

   string time;
   StringConcatenate(time,StringSubstr (str,0,4),".",StringSubstr(str,5,2),".",StringSubstr(str,8,2)," ",StringSubstr(str,11,2),":",StringSubstr(str,14,4));  

Yep. My bad ;(

Thanks :)

sathyaicm
17
sathyaicm  

Awesome!!!

Thanks Mladen Rakic It worked

Mladen Rakic
57567
Mladen Rakic  
sathyaicm:

Awesome!!!

Thanks Mladen Rakic It worked

Yes, but read this post too :

Alain Verleyen:

Yes it works with StringConcatenate(), but the mql5 version of this function is not the same as mql4.

   string time;

   StringConcatenate(time,StringSubstr (str,0,4),".",StringSubstr(str,5,2),".",StringSubstr(str,8,2)," ",StringSubstr(str,11,2),":",StringSubstr(str,14,4)); 


So it works within string concatenate too (if the first parameter is not omitted and is properly declared as variable)

It depends what form do you like more. I don't like StringConcatenate() (which is obvious:)) and I prefer using the + form (less code and simpler to follow) - but that depends on the style I guess

To add comments, please log in or register