I don’t know if I will answer this completely, but here it goes.
“is” and “isnot” are used when you want to compare the actual variable rather than the value of the variable. This is used mostly when comparing it to Nothing, like you would say string1 isNot Nothing, to check if the variable has been stored a value into it.
So, when looking at an empty string “”, that is the actual value that’s in the variable, rather Nothing is comparing if the variable has a value stored in it at all.
So if a variable = “”, then it has something and variable isNot Nothing will be True.
Lot of times you need to use a combination of these comparisons.
That example will return False if string1 is either Nothing or has an empty string.
If you were to just compare it with an empty string, then if the variable failed to store a value at all, you will get an Exception saying that there is no value in the variable.
Hi there @Ann,
You are checking both of these conditions simultaneously:
variable isNot Nothing
variable.ToString.Trim <> (“”)
As a result, in the event the variable is not initialised, you are checking if it is not nothing (perfectly fine), but also trying to access it to trim it (not fine).
To work around this, you can do as noted by @ClaytonM above, or use the below:
This ensures the second portion of the condition is only evaluated in the event the first was True. So we will only Trim the String and check it’s value, in the event it is not null.
Hi ClaytonM,
I am trying to check if the value is empty or null. If true then assign default value. If false - check the string length.
Your suggestion does not work unfortunately if I the string is not empty and I am trying to check the sting length then.
Your condition and the one JDavey and I presented, says if the variable is not nothing then check if the variable is not equal to empty string, else go to the false side. So, if the variable is Nothing or equals empty string, then it will go to the false side.
Let us know what exactly isn’t working and we’ll try to help. Also, verify that the variable is a value that was intended before the condition.