Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Global Variables

Status
Not open for further replies.

OraWiz

Programmer
Aug 17, 2003
37
IN
How can I use global variables Through out the application and forms (other than creating a property in the application object) like gvUSSER,gvREGION,gvDEPT etc...is there any other way, If yes please give a clue
Thanks
Sebastian
 
Hi

To make a variable GLOBAL put in code..

GLOBAL gcUSSER,gcREGION,gcDEPT

It is a way to quickly identify what type of variable we have createed.. we use some prefix notations.

g for global, l for local
c for character type
n for numeric type..
l for logical etc..

GLOBAL gcUser, gnUserNumber, glIsAllowed
LOCAL lcUser, lnUserNumber, llIsAllowed

SO reading the variable name, you understand more.

The declaration GLOBAL, LOCAL, PRIVATE etc make the variables in that way. But the real variable is when you assign value to it.

If you specify..
gcUser = 100 it is numeric, but only you will get misguided. so gnUser=100 or gcUser="Ramani" makes more sense to us.

:)

ramani :)
(Subramanian.G)
 
OraWiz

Avoid global variables if possible.

Instead use object or form properties.

To add a new form property, click on Form > New Property... on the menu and enter the name of the property.

To access the property from within the form use

THISFORM.dDate = DATE()

To access the property outside of the form use

oForm1.cName = [My name]

where oForm1 is the object reference of the form.


FAQ184-2483 - the answer to getting answered.​
Chris [pc2]
 
For VFP 7 use:

Public g_MyVariable

...this will give your variable global scope.

Slighthaze = NULL

[ul][li]FAQ184-2483
An excellent guide to getting a fast and accurate response to your questions in this forum.[/li][/ul]
 
Thanks a lot Ramani and Chris,Since I am using VFP 6 I can Use PUBLIC, GLOBAL is not working with me VFP6.
Any way PUBLIC will more than enough for me.
Once again Thanks alot.
Rgds
OraWiz
 
My God.. I noticed mistake in my reply.

Please read Global (command) as PUBLIC.
GLOBAL is not a command in VFP.

PUBLIC gcUSSER,gcREGION,gcDEPT
PUBLIC gcUser, gnUserNumber, glIsAllowed

I have to mention this so that future users dont get misguided. 'Global' is understood but the syntax has to be PUBLIC.

Just got into the trap that OraWiz called it global. Shhhhhhhh. Thanks Orawiz for coming back on this thread. I feel putting a star to you for coming back and letting us know and striking the mistake. The benefit is to the future users who might trod these threads and on their behalf atleast I should cast this vote.


ramani :)
(Subramanian.G)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top