Hi Bruce.
>Is there any reason to use a #DEFINEd constant instead of a local var? I've seen it done, but am not aware if the rationale, particularly when trying to debug...
I think Jim's answer most closely resembles my thoughts: it's an issue of scope. If you're only going to use the constant value in one place, I'd be tempted to either hard-code it or use a variable. However, the amazing thing about many constants is that they're often needed in lots of places.
For example, in SDT, I have a lot of constants that define where in the DBF header certain things go. Why not hard-code them? Well, things we often take for granted as constants may change with time. If MS changes the structure of the DBF header, I'd be hosed if I hard-coded the values. And, since I need those values in more than one place, it makes sense to define them as constants. Also, it's easier to read code that references something like cnDBF_CDX_BIT rather than 28.
In the case of SYS functions (which you mentioned in a later message), I'm not sure it makes sense, since the SYS function number will never change (or is that a bad assumption? [g]) and replacing the function number with a different one likely would require more than just a number change. In the case of MESSAGEBOX() (which George mentioned), it does make sense to me, mostly from a readability POV (ie. IF MESSAGEBOX(lcMessage, MB_YESNO + MB_ICONSTOP) = IDYES is easier to understand than IF MESSAGEBOX(lcMessage, 20) = 6).
Doug
Précédent
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement