Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
#DEFINE - Why?
Message
From
01/04/2008 00:29:15
 
 
To
31/03/2008 16:23:01
General information
Forum:
Visual FoxPro
Category:
Other
Title:
Environment versions
Visual FoxPro:
VFP 9 SP2
Miscellaneous
Thread ID:
01306848
Message ID:
01307227
Views:
9
>>>Not a very good example, only the TaxPercentage would be vible for a #define, since the other values are not constants.
>>
>>Not sure what you mean - the following works as expected:
>>
>>#DEFINE TaxAmount       _0lO1Ol
>>#DEFINE InvoiceSubTotal _0lOlOl
>>#DEFINE TaxPercentage   _0lO1O1
>>
>>* At runtime, set the values to whatever you want,
>>* or get a return value from a function, or pass them in as parameters, ...
>>InvoiceSubTotal = 25
>>TaxPercentage = 0.12
>>
>>TaxAmount = InvoiceSubTotal * TaxPercentage
>>
>>?TaxAmount  && 3
>>
>>
>Sorry. I don't understand how this works.
>#DEFINE TaxAmount       _0lO1Ol
>#DEFINE InvoiceSubTotal _0lOlOl
>#DEFINE TaxPercentage   _0lO1O1
>
>CLEAR
>
>* At runtime, set the values to whatever you want,
>* or get a return value from a function, or pass them in as parameters, ...
>InvoiceSubTotal = 25   && Doesn't this equate to _0lO1Ol = 25
>? _0lO1Ol              && but this generates an error
>
>TaxPercentage = 0.12   && Doesn't this also equate to _0lO1Ol = 25
>? _0lO1Ol              && but this generates an error
>
>TaxAmount = InvoiceSubTotal * TaxPercentage
>&&  Shouldn't this equate to  _0lO1Ol = _0lO1Ol * _0lO1Ol
>&&  or expand to _0lO1Ol = .12 * .12
>
>? taxamount
>?invoicesubtotal
>?taxpercentage
>? _0lO1Ol
>
>
>but the last four lines print the values assigned. If each constant is assigned the same value (_0lO1Ol), why do invoicesubtotal and taxpercentage have different values when it comes time to print them?

This is exactly my point. Look very closely at my 3 #DEFINEs, they are NOT the same, they're purposely chosen to look alike to a casual read. The whole idea is to obfuscate the code, make it hard to read, and it looks like it has worked perfectly!

Copy & paste the correct #DEFINEs in your ? lines that generate errors, and you'll see they don't. The errors you're seeing are because you're actually using the #DEFINE for TaxAmount, which hasn't been defined yet when you're ?ing them.
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform