Over the course of my interactions with Action!, for whatever reason, I never had a need for defining a string value. While numeric definitions are cake, string ones turned out not to be so much.
Let’s explore what I wanted to do. I wanted to compare a variable that was input against a static string. Why not just hard code the string? Well, it is used in multiple locations, and having it DEFINEd makes it easy to change in all of them at once. Thats the whole point of using DEFINE. The source code I wanted to write:
if SCompare(sA, SSREADY) = 0 then
So using a define for SSREADY in an INCLUDEd source file accomplishes the goal of making it easy to change in just one place and use it multiple times across projects. Something like this was needed for my code work:
DEFINE SSREADY = "TEST"
That works for numbers with no problem:
DEFINE NVAL = "100"
Anywhere that NVAL is found in the source, it will be replaced with 100.
So what is the issue? Used in the context of SCompare above, it ends up producing code like this:
if SCompare(sA, TEST) = 0 then
Obviously thats not the intent of the source and it won’t work, and the compiler will tell you so immediately. The compiler will think TEST is an undefined variable. The word TEST needs double quotes around it. Thats the goal.
Reading through the manual you will understand that in order to print double quotes, you have to precede each one with another. Such as:
PrintE("Hello ""world""!")
which produces the output:
Hello "world"!
So moving back to the DEFINE statement it appears it needs to look like this:
DEFINE SSREADY = ""TEST""
But that doesn’t work either. The compiler doesn’t like it. The solution is to wrap the dual double quoted value in another set of double quotes. But there is a caveat – they can not be all run together, or the compiler doesn’t understand which two of the 3 should be translated into a single double quote. So you need to place a space between the DEFINE’s double quotes and the values double quote pair. The proper syntax for DEFINEing a string value is:
DEFINE SSREADY = " ""TEST"" "
Here is a sample program that demonstrates this concept:
DEFINE NVAL = "100" DEFINE SVAL = " ""TEST"" " PROC Main() PrintF("NVAL=[%B]%E",NVAL) PrintF("SVAL=[%S]%E",SVAL) RETURN
This will properly produce the output desired, and also allow for use in my original use case – SCompare().