Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Ken Murphy
  Where is Ken Murphy?
 Springhill
 Canada
 Ken Murphy
 To: George Kelly
  Where is George Kelly?
 Dromore
 United Kingdom
 George Kelly
 Tags
Subject: RE: maximizing my applications main screen
Thread ID: 110937 Message ID: 115390 # Views: 3 # Ratings: 0
Version: Visual FoxPro 9 Category: Forms
Date: Thursday, December 07, 2006 1:44:55 PM         
   


> > Ive declared a public variable m.addtofont in my Menu SETUP code.
> >
> > I can tell you that, as a consultant, if I am asked to work on someone elses code, I raise my rate for each PUBLIC devclarartion that I find < s >.
> >
> > There are better ways to do things than by using public variables.
> >
> > If you need something that is available for the life of your app, you can declare it as PRIVATE very early in your main startup program and it will be available until you quit the app.
> >
> >
> > Regards,
> > Marcia G. Akins
> > Tightline Computers, Inc.

>
> Why do you disapprove of the use of PUBLIC variables in such an application, Marcia?
>
> George

George,

Public variables are visible EVERYWHERE. This means that they are visible anywhere in your app, but they are also changeable anywhere in your app. In VFP, it is quite acceptable for you to do the following.

PUBLIC MyPublicVar
MyPublicVar = 0
MyPublicVar = [This is Text]
MyPublicVar = .f.
MyPublicVar = NULL
RELEASE MyPublicVar


In fact, you could copy this code directly into the command window and run it and you would not get an error. Because public variables are visible anywhere in the app, after the PUBLIC declartion, each of these lines of code could run from anywhere in the app. While each of these lines of code would run without error, another line of code may not.

Lets say that you declare m.addtofont PUBLIC in your Main.Prg and then in one of your forms, your code issues a

m.addtofont = .F.

and then the user closes the form. This will run without error. Now, your user attempts to open another form and your code tries to do addition using m.AddToFont. That WILL give you an error - and it will be an error that is VERY difficult to find. (You can be pretty sure that your user will not remember which form was opened previously.)

Like Marcia, I too HATE public variables. There are times that you need to use them, but I tend to avoid public variables where ever possible.

You might want to consider storing this value in a table located in your users c:\Documents and Settings\UserName\Application Data\MyApp directory. This is probably something that your user would want to retain from one session to the next. If you save it to a table, you can open the table with the form, and you would be able to see it anywhere in that form, but it would not be a public variable. You would not be permitted to

REPLACE MyTable.nAddToFont WITH .F.


Hope this helps.

Ken
You shall know the truth - and the truth shall set you free. (John 8:33)

ENTIRE THREAD

maximizing my applications main screen Posted by Jahangir Khan @ 10/24/2006 10:41:17 AM
RE: maximizing my applications main screen Posted by Kiran Kumar Singh @ 10/24/2006 10:57:45 AM
RE: maximizing my applications main screen Posted by Saeed Afshari @ 10/24/2006 10:58:31 AM
RE: maximizing my applications main screen Posted by Borislav Borissov @ 10/24/2006 10:58:32 AM
RE: maximizing my applications main screen Posted by Dave Crozier @ 10/24/2006 10:59:29 AM
RE: maximizing my applications main screen Posted by Marcia Akins @ 10/24/2006 12:19:34 PM
RE: maximizing my applications main screen Posted by George Kelly @ 11/15/2006 10:53:09 AM
RE: maximizing my applications main screen Posted by Marcia Akins @ 12/6/2006 11:55:15 PM
RE: maximizing my applications main screen Posted by George Kelly @ 12/7/2006 10:52:23 AM
RE: maximizing my applications main screen Posted by Marcia Akins @ 12/7/2006 12:40:34 PM
RE: maximizing my applications main screen Posted by George Kelly @ 12/7/2006 1:08:03 PM
RE: maximizing my applications main screen Posted by Ken Murphy @ 12/7/2006 1:44:55 PM
RE: maximizing my applications main screen Posted by tushar @ 12/7/2006 3:26:59 PM
RE: maximizing my applications main screen Posted by Ken Murphy @ 12/7/2006 3:31:52 PM
RE: maximizing my applications main screen Posted by George Kelly @ 12/7/2006 4:51:26 PM
RE: maximizing my applications main screen Posted by Ken Murphy @ 12/7/2006 6:07:40 PM
RE: maximizing my applications main screen Posted by George Kelly @ 12/7/2006 9:23:25 PM
RE: maximizing my applications main screen Posted by Don Higgins @ 12/7/2006 11:20:46 PM
RE: maximizing my applications main screen Posted by George Kelly @ 12/8/2006 11:21:35 AM
RE: maximizing my applications main screen Posted by Ken Murphy @ 12/7/2006 3:29:56 PM
RE: maximizing my applications main screen Posted by Don Higgins @ 12/7/2006 11:22:33 PM
RE: maximizing my applications main screen Posted by George Kelly @ 12/6/2006 1:14:45 PM
RE: maximizing my applications main screen Posted by Barbara Peisch @ 10/24/2006 10:16:51 PM
RE: maximizing my applications main screen Posted by Mike Gagnon @ 10/25/2006 11:43:05 AM