I’m using PowerBuilder and have a problem with the if condition. I want to check if a variable is not null or it is not empty.
So first I have following if condition to test if the variable is null or not:
IF IsNull(ls_name) THEN
messagebox("ls_name", "is null") //true
else
messagebox("ls_name", "is not null")
end if
From the above condition, I know that ls_name is null. Now I test if its empty or not:
if ls_name = "" then
messagebox ("ls_name", "is empty")
else
messagebox("ls_name", "is not empty") //true
end if
And i get that ls_name is not empty.
Now when I use an if condition to check if ls_name is NOT Null or it is NOT empty, I put the following if condition:
IF not IsNull(ls_name) or ls_name <> "" THEN
messagebox("test", "condition true")
else
messagebox("test", "condition false") //this becomes true.
end if
It goes to the else part of the condition. Shouldn’t the if part become true? Am I writing the if condition wrong?
Thinking of “null” as “unknown” has always gotten me by in understanding how expressions evaluated.
So, when ls_name is null,
evaluates to
or
Well, for an OR to evaluate to TRUE, at least one condition must be TRUE. That doesn’t apply in this case.
The way I usually test for this is:
which, when ls_name is null, resolves to
then
and
In other words, the variable is “empty”.
Good luck,
Terry