Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Dan Roche
  Where is Dan Roche?
 Batavia
 Illinois - United States
 Dan Roche
 To: Ken Murphy
  Where is Ken Murphy?
 Springhill
 Canada
 Ken Murphy
 Tags
Subject: RE: #define versus assigning value to a public variable
Thread ID: 104562 Message ID: 104572 # Views: 2 # Ratings: 0
Version: Visual FoxPro 6 Category: Other
Date: Thursday, August 17, 2006 7:05:45 PM         
   


> > What's the difference between using #define and just assigning a value to a variable?
> >
> >
> > #define CRLF chr(13)+chr(10)
> > 

> > or
> >
> > CRLF = chr(13)+chr(10)
> > 

> >
> > Also, is there any reason why the #define statement above wouldn't work? It didn't seem to take for me, or at least when I tried to use it, I got a "Variable crlf not defined" error.
> >
> > Thanks
> >
> > PC Load Letter???!!!!!!!

>
> Dan,
>
> As Jim mentioned a #DEFINE is evaluated at compile, so it means that if the value is going to change, you are better off using a variable. In a CRLF situation, it is unlikely that you would ever want to change the value represented by CRLF, so #DEFINE is the way to go. If on the other hand you were talking about #DEFINE PAGELENGTH 8.5, you should probably use a variable - otherwise, you would give yourself problems when you tried to use legal sized paper. Another example might be in defining lable captions. In Canada, we have two offical languages (French & English) therefore I have to be able to produce my apps for both languages. One way to handle this is to #DEFINE each lablel caption. For example,
>
#DEFINE DateOfBirthLblCaption [Date of Birth]

> Now you can send your .H file to a translator and have the translator translate everything within the square brackets and you would end up with
>
#DEFINE DateOfBirthLblCaption [Date de Naisance] && or however it is spelled in French

> Recompile using the French language resource files and you now have a French language app. As you can see though, you have to do a recompile. If you wanted to do language conversion on the fly, you would be better off using a table and a select command like
>
SELECT CaptionID, Caption FROM CaptionsTable WHERE CaptionsTable.LanguageID = goApp.CurrentLanguage

>
> As to why it doesn't work? Store all of your #DEFINE's in a text file with a ".H" extension. In a .PRG, you would issue a #INCLUDE [Path2\MyDefinitionsFile.h] In a form or a class, however you need to use the VFP menu to attach the .H file. Go to the Class or Form menu and select the "Include File" option. Navigate to your .H file and there you have it.
>
> Hope this helps,
>
> Ken
> You shall know the truth - and the truth shall set you free. (John 8:33)


mmhmm. Thanks Jim, Brad, and Ken. I feel better now :)

PC Load Letter???!!!!!!!

ENTIRE THREAD

#define versus assigning value to a public variable Posted by Dan Roche @ 8/17/2006 4:21:18 PM
RE: #define versus assigning value to a public variable Posted by Jim Winter @ 8/17/2006 4:40:56 PM
RE: #define versus assigning value to a public variable Posted by Brad Schulz @ 8/17/2006 5:53:53 PM
RE: #define versus assigning value to a public variable Posted by Ken Murphy @ 8/17/2006 6:03:43 PM
RE: #define versus assigning value to a public variable Posted by Dan Roche @ 8/17/2006 7:05:45 PM
RE: #define versus assigning value to a public variable Posted by Borislav Borissov @ 8/17/2006 7:40:52 PM
RE: #define versus assigning value to a public variable Posted by Andy Kramek @ 8/18/2006 11:58:15 AM
RE: #define versus assigning value to a public variable Posted by Borislav Borissov @ 8/18/2006 12:12:23 PM
RE: #define versus assigning value to a public variable Posted by Andy Kramek @ 8/18/2006 12:20:07 PM
RE: #define versus assigning value to a public variable Posted by Borislav Borissov @ 8/18/2006 1:05:49 PM
RE: #define versus assigning value to a public variable Posted by Bernard Bout @ 8/19/2006 5:37:30 PM
RE: #define versus assigning value to a public variable Posted by Andy Kramek @ 8/19/2006 8:27:20 PM
RE: #define versus assigning value to a public variable Posted by Ken Murphy @ 8/20/2006 3:48:45 AM
RE: #define versus assigning value to a public variable Posted by Bernard Bout @ 8/20/2006 6:57:01 PM
RE: #define versus assigning value to a public variable Posted by Bernard Bout @ 8/20/2006 6:59:14 PM