Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
#DEFINE - Why?
Message
From
01/04/2008 01:35:02
 
 
To
01/04/2008 00:29:15
General information
Forum:
Visual FoxPro
Category:
Other
Title:
Environment versions
Visual FoxPro:
VFP 9 SP2
Miscellaneous
Thread ID:
01306848
Message ID:
01307232
Views:
8
>>>>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.


You've made your point. I knew what you were trying to do, but I stared and stared and never saw the differences. I should have run them through some test to see the differences but (in the words of the Chad Mitchel Trio song I "trusted my eyes and a little bit later got quite a surprise"
Previous
Reply
Map
View

Click here to load this message in the networking platform