stevehopwoodforex.com
https://www.stevehopwoodforex.com/phpBB3/
Print view

implicit conversion from number to string
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=5328
Page 1 of 1
Author:  traderduke [ Thu Nov 16, 2017 3:56 pm ]
Post subject:  implicit conversion from number to string

coders
When I changed line 16 to line 18 I got this warning, it affects the back ground coloring. I 've triedthe str string function on line 17 but I can't seem to get the syntax correct.

Any help would be appreciated
Ray

String Number to string.docx
Author:  simplex [ Thu Nov 16, 2017 7:07 pm ]
Post subject:  implicit conversion from number to string

In your new macro version you concatenate several strings and numbers to a new string.

Issue 1 - syntactical: missing explicit conversion of numbers - see IntegerToString and DoubleToString in the mq4 reference manual for details.

Issue 2 - methodical: macro version is obviously intended to hold a version name - a constant inside your project. By adding input parameters you turn the constant into a variable. It would be better to add parameter information directly to variable shortname. Later code maintenance should be easier then.
Author:  renexxxx [ Thu Nov 16, 2017 7:23 pm ]
Post subject:  implicit conversion from number to string

The MQL4 compiler is warning you that it needs to convert an integer to a string, in order to concatenate the expression into a longer string in:

Code: Select all

shortName=indicatorName+""+version+" - id"+almostUniqueIndex;
here, version is an integer, that is implicitly converted to a string.

Your options are:

1.

Code: Select all

shortName=indicatorName+(string)version+" - id"+almostUniqueIndex;
In here, version is explicitly converted to a string.

2,

Code: Select all

shortName=StringConcatenate(indicatorName, version, " - id", almostUniqueIndex);
as StringConcatenate takes arguments of any type.

3.

Code: Select all

shortName=StringFormat("%s%d - id%s", indicatorName, version, almostUniqueIndex);
In here, the first %s is replaced with the string indicatorName, %d is replaced with the integer version and the second %s is replaced with the string almostUniqueIndex.

You can also use the function IntegerToString, as Simplex suggested, to convert the integer to a string.

R.
Author:  traderduke [ Sun Nov 19, 2017 3:35 pm ]
Post subject:  implicit conversion from number to string

Thanks fellows for the help! Using the shortName for all info with "StringConcantenate" seems to be my best option since I'm always mixing apples & oranges.

Thanks Again
Ray
All times are UTC Page 1 of 1