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

Back to topics list To post a new topic, please log in or register
avatar
6
4XNZ 2014.05.23 21:05
 

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;

   } 


avatar
164
drazen64 2014.05.24 00:13 #
 

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". 

 

 

avatar
164
drazen64 2014.05.25 03:09 #
 

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;

   } 

 

 

avatar
6
4XNZ 2014.06.07 07:04 #
 
Thank you.
avatar
6
4XNZ 2016.03.30 07:08 #
 
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. 
avatar
13009
WHRoeder 2016.03.30 14:48 #
 
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      );

Back to topics list  

To add comments, please log in or register