You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
MathIsValidNumber() accepts a double. Please check the documentation.
You are giving it a string.
If you didn't keep ignoring my comments about using #property strict you would see the compiler warns you about this.
If you take a string of letters and make it into a double, the value of the double becomes 0.
0 is a valid number.
Hence why your code is returning true.
MathIsValidNumber() accepts a double. Please check the documentation.
You are giving it a string.
If you didn't keep ignoring my comments about using #property strict you would see the compiler warns you about this.
If you take a string of letters and make it into a double, the value of the double becomes 0.
0 is a valid number.
Hence why your code is returning true.
But you did not tell me in your answer that MathIsValidNumber() compares double only, and not strings. By the way, which number is not a valid number? Except complex numbers or infinities, and who wants to use them in MQL4 by the way. Anyhow, the "Keyword" seems misleading.
But you did not tell me in your answer that MathIsValidNumber() compares double only, and not strings.
I presumed you might have bothered to check the documentation...
And if you didn't keep ignoring my advice about #property strict...
So I now ask again, what is the command to tell the compiler to decide is a variable holds a string and not any form of number? Thank you for your anticipated answer.
If you don't expect the value to ever be 0, type-cast the string to a double and test that it isn't equal to 0.
I presumed you might have bothered to check the documentation...
And if you didn't keep ignoring my advice about #property strict...
If you don't expect the value to ever be 0, type-cast the string to a double and test that it isn't equal to 0.
But What happens to the number zero. I presume it is a double value as well as integer value. When you cast string it returns 0, when you input 0, it returns 0. So...?
Yep, that is a problem.
You could do a string comparison if the cast value = 0
i.e. if(cast_value == 0 && str_value == "0")
But you would have to think about 0.0 or 0.00 being entered.
You could burst the string into a character array and test each character.
Depends how important this is.
{
//---
ObjectCreate("SimultaneousReleaseIndex1",OBJ_LABEL,0,0,0);
ObjectSetString(0,"SimultaneousReleaseIndex1",OBJPROP_TEXT,"Four");
ObjectCreate("SimultaneousReleaseIndex2",OBJ_LABEL,0,0,0);
ObjectSetString(0,"SimultaneousReleaseIndex2",OBJPROP_TEXT,"44");
ObjectCreate("SimultaneousReleaseIndex3",OBJ_LABEL,0,0,0);
ObjectSetString(0,"SimultaneousReleaseIndex3",OBJPROP_TEXT,"Forty4");
ObjectCreate("SimultaneousReleaseIndex4",OBJ_LABEL,0,0,0);
ObjectSetString(0,"SimultaneousReleaseIndex4",OBJPROP_TEXT,".1234567890");
if(IsNumeric(ObjectGetString(0,"SimultaneousReleaseIndex1",OBJPROP_TEXT)))
Print("text1 is numeric");
if(IsNumeric(ObjectGetString(0,"SimultaneousReleaseIndex2",OBJPROP_TEXT)))
Print("text2 is numeric");
if(IsNumeric(ObjectGetString(0,"SimultaneousReleaseIndex3",OBJPROP_TEXT)))
Print("text3 is numeric");
if(IsNumeric(ObjectGetString(0,"SimultaneousReleaseIndex4",OBJPROP_TEXT)))
Print("text4 is numeric");
}
//---
bool IsNumeric(string text)
{
int length=StringLen(text);
for(int i=0;i<length;i++)
{
int char1=StringGetChar(text,i);
if((char1>47 && char1<58) || char1==46)
continue;
else
return(false);
}
return(true);
}
//+------------------------------------------------------------------+
{
//---
ObjectCreate("SimultaneousReleaseIndex1",OBJ_LABEL,0,0,0);
ObjectSetString(0,"SimultaneousReleaseIndex1",OBJPROP_TEXT,"Four");
ObjectCreate("SimultaneousReleaseIndex2",OBJ_LABEL,0,0,0);
ObjectSetString(0,"SimultaneousReleaseIndex2",OBJPROP_TEXT,"44");
ObjectCreate("SimultaneousReleaseIndex3",OBJ_LABEL,0,0,0);
ObjectSetString(0,"SimultaneousReleaseIndex3",OBJPROP_TEXT,"Forty4");
ObjectCreate("SimultaneousReleaseIndex4",OBJ_LABEL,0,0,0);
ObjectSetString(0,"SimultaneousReleaseIndex4",OBJPROP_TEXT,".1234567890");
if(IsNumeric(ObjectGetString(0,"SimultaneousReleaseIndex1",OBJPROP_TEXT)))
Print("text1 is numeric");
if(IsNumeric(ObjectGetString(0,"SimultaneousReleaseIndex2",OBJPROP_TEXT)))
Print("text2 is numeric");
if(IsNumeric(ObjectGetString(0,"SimultaneousReleaseIndex3",OBJPROP_TEXT)))
Print("text3 is numeric");
if(IsNumeric(ObjectGetString(0,"SimultaneousReleaseIndex4",OBJPROP_TEXT)))
Print("text4 is numeric");
}
//---
bool IsNumeric(string text)
{
int length=StringLen(text);
for(int i=0;i<length;i++)
{
int char1=StringGetChar(text,i);
if((char1>47 && char1<58) || char1==46)
continue;
else
return(false);
}
return(true);
}
//+------------------------------------------------------------------+
Yep, that is a problem.
You could do a string comparison if the cast value = 0
i.e. if(cast_value == 0 && str_value == "0")
But you would have to think about 0.0 or 0.00 being entered.
You could burst the string into a character array and test each character.
Depends how important this is.
Yep, that sort of thing.
You'd need to be careful about:
Yep, that sort of thing.
You'd need to be careful about:
Ernst Van Der Merwe: