Download MetaTrader 5

is there a way to suppress StringFormat from substituting "(missed string parameter) " for missed parameters?

To add comments, please log in or register
David Ewing
28
David Ewing  

I would like to substitute individual variables in a controlled fashion such that changes to a struct can be managed. 


//                   -F- -?v- -s- ----xcn----  ----gmt----  -m- -g- --tz-- -?d-?l-  -dlst- -r-

string mpformat = ",,%s  ,%i ,%s ,%s,%s,%s,%s ,%s,%s,%s,%s, ,%i ,%d ,%s,%s ,%i,%i%  ,%i,%i ,%s"; 

void printMarketProfile (int x){

   string s = mpformat;

   

   s = StringFormat(s ,__FUNCTION__);    s = StringFormat(s ,_mkts[x].reason    ,_mkts[x].symbol    );

   s = StringFormat(s ,_mkts[x].xcnopen0  ,_mkts[x].xcnclose0 ,_mkts[x].xcnopen1 ,_mkts[x].xcnclose1);

   s = StringFormat(s ,_mkts[x].gmtopen0  ,_mkts[x].gmtclose0 ,_mkts[x].gmtopen1 ,_mkts[x].gmtclose1);

   s = StringFormat(s ,_mkts[x].marketcap ,_mkts[x].gmt2xcn   );

   s = StringFormat(s ,_mkts[x].timezone0 ,_mkts[x].timezone1 );

   s = StringFormat(s ,_mkts[x].hasDST    ,_mkts[x].hasLunch  ,_mkts[x].isSouthernHemisphere);

   s = StringFormat(s ,_mkts[x].dst0      ,_mkts[x].dst1      );

   Print(s);

   return;

   } 

Drazen Penic
2677
Drazen Penic  

Just curious, is this code working on any version of MT4?

I just tried and after the line  

 s = StringFormat(s ,__FUNCTION__);

"s" equals to 

,,printMarketProfile  ,0 ,(missed string parameter) ,(missed string parameter),(missed string parameter),(missed string parameter),(missed string parameter) ,(missed string parameter),(missed string parameter),(missed string parameter),(missed string p

 and subsequent StringFormat() calls do nothing because first call "consumed" all format specifiers.

This is with MT4 v646, tried with and without "strict mode". 

Drazen Penic
2677
Drazen Penic  

Nope, no way.

Here's an idea: split your format string into pieces, then create strings  and concat them.

Something like: 

string mpformat1 = ",,%s  ,%i ,%s"; 
string mpformat2 = "%s,%s,%s,%s ,%s,%s,%s,%s, ,%i ,%d ,%s,%s ,%i,%i%  ,%i,%i ,%s"; 

void printMarketProfile (int x){

  

   s = StringFormat(mpformat1 ,__FUNCTION__,_mkts[x].reason    ,_mkts[x].symbol    );

   s += StringFormat(mpformat2 ,_mkts[x].xcnopen0  ,_mkts[x].xcnclose0 ,_mkts[x].xcnopen1 ,_mkts[x].xcnclose1 ....);

   Print(s);

   return;

   } 
David Ewing
28
David Ewing  
Thank you.
David Ewing
28
David Ewing  
drazen64:

Just curious, is this code working on any version of MT4?

I just tried and after the line  

"s" equals to 

 and subsequent StringFormat() calls do nothing because first call "consumed" all format specifiers.

This is with MT4 v646, tried with and without "strict mode". 

 

 

belated thank you. 
whroeder1
15584
whroeder1  
As drazen64 already pointed out, StringFormat  requires all values.
   s = StringFormat(s ,__FUNCTION__);    s = StringFormat(s ,_mkts[x].reason    ,_mkts[x].symbol    );
   s = StringFormat(s ,_mkts[x].xcnopen0  ,_mkts[x].xcnclose0 ,_mkts[x].xcnopen1 ,_mkts[x].xcnclose1);
   s = StringFormat(s ,_mkts[x].gmtopen0  ,_mkts[x].gmtclose0 ,_mkts[x].gmtopen1 ,_mkts[x].gmtclose1);
   s = StringFormat(s ,_mkts[x].marketcap ,_mkts[x].gmt2xcn   );
   s = StringFormat(s ,_mkts[x].timezone0 ,_mkts[x].timezone1 );
   s = StringFormat(s ,_mkts[x].hasDST    ,_mkts[x].hasLunch  ,_mkts[x].isSouthernHemisphere);
   s = StringFormat(s ,_mkts[x].dst0      ,_mkts[x].dst1      );
Either provide all of them
s = StringFormat(s ,__FUNCTION__
                   ,_mkts[x].reason    ,_mkts[x].symbol
                   ,_mkts[x].xcnopen0  ,_mkts[x].xcnclose0 ,_mkts[x].xcnopen1 ,_mkts[x].xcnclose1
                   ,_mkts[x].gmtopen0  ,_mkts[x].gmtclose0 ,_mkts[x].gmtopen1 ,_mkts[x].gmtclose1
                   ,_mkts[x].marketcap ,_mkts[x].gmt2xcn
                   ,_mkts[x].timezone0 ,_mkts[x].timezone1
                   ,_mkts[x].hasDST    ,_mkts[x].hasLunch  ,_mkts[x].isSouthernHemisphere
                   ,_mkts[x].dst0      ,_mkts[x].dst1      );
Or make substrings.
string xcn = StringFormat("%s,%s,%s,%s", _mkts[x].xcnopen0  ,_mkts[x].xcnclose0 ,_mkts[x].xcnopen1 ,_mkts[x].xcnclose1);
string gmt = StringFormat("%s,%s,%s,%s", _mkts[x].gmtopen0  ,_mkts[x].gmtclose0 ,_mkts[x].gmtopen1 ,_mkts[x].gmtclose1);
string tz  = StringFormat("%i,%i",       mkts[x].timezone0 ,_mkts[x].timezone1 );
string dlst= StringFormat("%i,%i",       _mkts[x].hasDST    ,_mkts[x].hasLunch  ,_mkts[x].isSouthernHemisphere);
//                       -F- -v- -s- -xcn- -gmt-  -m- -g-  -tz-  -?d-?l- -dlst- -r-
string s   = StringFormat("%s,%s,%s" ",%s" ",%s" ",%s,%s" ",%s" ",%s,%s" ",%s" ",%s,%s"
                         ,__FUNCTION__, _mkts[x].reason, _mkts[x].symbol
                         ,xcn
                         ,gmt,
                         ,mkts[x].marketcap ,_mkts[x].gmt2xcn
                         ,dlst
                         ,mkts[x].dst0      ,_mkts[x].dst1      );
To add comments, please log in or register