Hi,
I've read https://www.mql5.com/en/forum/46695, but I still don't know how to test, if a string == NULL.
The following results in false:
So what's the solution?
Thanx.
NULL is an int equalling 0
try this . . .
string Str; string NullStr; Str = ""; if(Str == NullStr) Print("True !!"); else Print("False !!");
Don't create null strings, always initialize them.
The sentence is misleading. As far as I noticed there are no null strings in MQL. There are only null-terminated strings. Every variable in MQL is initiated (to its default), even if it is declared. Moreover, in the case the Str was explicitly set to "0", while the NullStr was initialized implicitly to "".
ERR_NOT_INITIALIZED_STRING | 4008 | Not initialized string. |
ERR_NOT_INITIALIZED_ARRAYSTRING | 4009 | Not initialized string in array. |
Maybe my problem get's clearer, when I describe, why I need the NULL string comparison:
I've programmed a functional layer around the timeseries functions (iClose, iOpen, iBarShift, ...).
This layer identifies, if the current chart is an offline chart or not and depending on that either calls the timeseries functions above or
my own functions, which directly operate on the history files.
Since all the timeseries functions allow to submit NULL as the parameter for symbol,
I need a way to check, if the parameter is NULL, in order to replace it by symbol() when calling my own functions.
Maybe my problem get's clearer, when I describe, why I need the NULL string comparison:
I've programmed a functional layer around the timeseries functions (iClose, iOpen, iBarShift, ...).
This layer identifies, if the current chart is an offline chart or not and depending on that either calls the timeseries functions above or
my own functions, which directly operate on the history files.
Since all the timeseries functions allow to submit NULL as the parameter for symbol,
I need a way to check, if the parameter is NULL, in order to replace it by symbol() when calling my own functions.
The parameter that you use in the function call ? why do you need to check ? it's you that sets it.
Can you give an example of how/why you need to check this . . .
@RaptorUK: I know that I can circumvent the problem. But I just want my functional layer to behave the same way as the timeseries functions,
so I want to call e.g. HstiClose(NULL, 0, shift).
@WHRoeder: MarketInfo(Symbol(), MODE_TICKSIZE) tells me, if the chart is an offline chart or not.
But let's not further dive into my intentions.
Is there a way to check, if Str == NULL?
It would be a strange thing in MQL allowing the assignment Str = NULL without providing the option to check for something like Str == NULL.
@RaptorUK: I know that I can circumvent the problem. But I just want my functional layer to behave the same way as the timeseries functions,
so I want to call e.g. HstiClose(NULL, 0, shift).
@WHRoeder: MarketInfo(Symbol(), MODE_TICKSIZE) tells me, if the chart is an offline chart or not.
But let's not further dive into my intentions.
Is there a way to check, if Str == NULL?
It would be a strange thing in MQL allowing the assignment Str = NULL without providing the option to check for something like Str == NULL.
Did you understand what I meant when I wrote . . .
. . . NULL is not a string, as you can see in the examples about Type Casting
You can do what you want but it's up to you to handle what happens when you pass the integer value of NULL to your function . . . for example:
I am also confused about the coding part, if it is initializing zero then how could it get the proper answer.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
I've read https://www.mql5.com/en/forum/46695, but I still don't know how to test, if a string == NULL.
The following results in false:
So what's the solution?
Thanx.