PDA

View Full Version : How to verify if a variable contains a string or not.


kornalius
12-12-2007, 06:48 PM
In PPL, there are no variable types per say but variables can contain either strings or numeric values.

If you do the following:

If (a$ <> NULL)
* ShowMessage("ok");
end;

It will never show the "ok" message because NULL value is really the numeric value 0 and the variable A$ defaults to numeric value of 0.

If A$ is assigned to an empty string:

A$ = "";
If (a$ <> NULL)
* ShowMessage("ok");
end;

It will show the "ok" message no problem.

HOWEVER, if A$ contains the following string value "0", then your condition becomes a problem. PPL tries to convert strings into numeric values when they are compared against a numeric value.

String value "0" = 0 in numeric value.

So the condition will not trigger even though there is a string value.

The best way is to use the IsNull() function:

a$ = "NOT NULL";

if (!IsNull(a$))
* ShowMessage("ok");
end;

No matter what the string value in A$, if there is a string content, empty "" or not, it will return True.

Donone
12-13-2007, 11:02 AM
Thank you for that useful and valuable piece of information, I shall copy it to my manual, which I do with all these snippets.