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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

program files are like standard module in VB ?

Status
Not open for further replies.

cvsubbarao

Programmer
Jun 22, 2000
3
0
0
US
I am basically Visual Basic progrmmer. Now I am going to work in VFP for my new project.
I want some information regarding program files.
Is it works same like standard module in VB?

If I call Set procedure to "program file" in VFP form load, can I access the procedures in the file to all of my events in the form or shall I call set procedure to for each event.

I have one more doubt. In VB I can create global variable in standard module. So I can access and assign the value of the variable in any of the form of the project. Is any way to use the same in VFP? I want to show the login user name in all of my forms in VFP.





 
Yes, a PUBLIC variable is one that can be accessed from anywhere in your program. They can be declared anywhere.

Also, SET PROCEDURE TO is permanent until you issue another SET PROCEDURE command. Just issue it in your startup PRG (or your form LOAD) and it will be available to all of your form events/methods.

Ian
 
You are correct.

The only differences with "Global" variables in VFP are:
For a variable to exist, the code "declaring" it has to execute... there is no "declarations" section at the top of any module. SO, the three ways to create global variables are:
1) Just use it in the highest level program in your app:
In MAIN.PRG:
gvcUserName = "" && Initialize
* or:
STORE "" TO gvcUserName, gvcOne, gvcTwo, gvcThree && Initialize a bunch at the same time
2) Declare the variable "PUBLIC" in any program (can be in top level program). eg:
In MAIN.PRG:
SET PROC TO common.prg
DO DefGlobs
In COMMON.PRG:
PROCEDURE whatever
RETURN
PROCEDURE DefGlobs
RELEASE gvcUserName && Release it first... can't PUBLIC an existing variable
PUBLIC gvcUserName
gvcUserName = "" && initialize it
RETURN
3) Declare the globals PRIVATE in the Top level program:
In MAIN.PRG:
PRIVATE gvcUserName
gvcUserName = "" && initialize it

****
The one Catch to VFP "global" variables is that they (like any other vfp variable) disappear (get "hidden") if you use them as a parameter. eg:
In MAIN.PRG:
gvcA = "A"
gvcB = "B"
DO DemoProc WITH gvcA
PROCEDURE DemoProc( pcA )
?pcA && This works
?gvcB && this Works
?gvcA && This Fails with a Variable not found error.
LIST MEMO && This shows that gvcA is "Hidden"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top