The Assignment Which Doesn't Happen

"I passed an argument to a script, set a local variable to the argument, but it was still zero (or empty string) at run time!"

What's wrong with this code?

String szMyString
int nFromArg = nArg1

If nFromArg = 1 THEN
{ some code }
else
{ alternative code }
end if

Answer: One odd thing about the PowerBuilder compiler is that it allows this code to compile without error but the code doesn't function as you might think since it does not set the value of the incoming parameters until after defining the local variables. Because of this, the value of nFromArg in the above script is 0, no matter what is passed in through nArg1. This can be an annoying little 'feature' until you understand it

Back

Home