Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
'Variable Not Found' strangeness
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01065229
Message ID:
01065653
Views:
15
>I am running VFP 6.0 and am seeing what I think to be oddities in the way I am receiving the simple 'Variable Not Found' Error..
>
>For instance, from the Command Window, I can type:
>
>? isnull(x)
>
>when x is not defined and get the error. likewise, when i run the command:
>
>? vartype(x)
>
>i see that vartype returns a 'U' for 'Undefined'...here's where it gets weird...
>
>We had a report from the field that a customer was receiving this error *randomly* when performing a certain set of steps. I stepped through the code using their explanation of what they were doing and indeed found a scenario where a variable(x), which is referenced at the very end of the method, could possibly not get defined earlier in the method. Since the variable(x) is only referenced twice in this function(once when it is defined, and once when it is later referenced), I naturally assumed this is where the error is occurring...here are those two pieces of code:
>
>&& DEFINITION
>lnPL1Price = PLD_BasePrice && this is where the variable is defined,I assume this means
> && it is defined as a global since there is no 'Local'
> && declaration before this
>&& REFERENCE
>replace t_TransactionItems.PL1Price with iif(isnull(lnPL1Price),; t_TransactionItems.SellingPrice,t_TRANSACTIONITEMS.QUANTITYSOLD * lnPL1Price)
>
>But when I step through the code in a debugger, and get to the Reference, I can plainly see at that point that the vartype of lnPl1Price is 'U' but the command executes without error, as if the variable was NULL instead of undefined..
>
>Why is it not giving me the error like it does in the command window? any ideas?

First, variables not declared as being either PUBLIC or LOCAL are PRIVATE, not PUBLIC or global. This means that any procedure or function called from the program declaring it can access and modify it.

Second, I'd have to think long and hard before using a PUBLIC variable. Simply too many problems associated with them is the reason. I'd use parameters or constants instead.

Third, I have a feeling that somewhere along the line the problem has to do with PLD_BasePrice being referenced and it being PRIVATE or not declared at all in terms of scope. This would mean that if the calling routine to the assignment statement did hit a line of code that initialized it to a value, it doesn't exist. PUBLIC and LOCAL variables carry a default value of false. PRIVATE variables don't exist until they're assigned.
George

Ubi caritas et amor, deus ibi est
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform