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

It's stupid question but I must ask 1

Status
Not open for further replies.

EKC

Technical User
Jan 13, 2001
43
0
0
CA
Hello friends,
I'm ashamed to ask this question but I need to (I guess being beginner in VFP gives me that right).So here comes the question:Where do you declare a function?
I have my little project that have only one form where user enter information in the boxes and command button which has code that make report based on criteria user enter on form.I don't have any .prg files in my project.Now I need to use user defined function but I don't know where to put it.I tried adding new program but it didn't work ?So my stupid questions are:Where to declare function and How to make the call to that function from command button click event?
Sorry if I make anyone upset but all book I have on VFP are advanced and I didn't find any for begginer(or dummy)

Thanks,
Lyn
 
There a a couple of ways.

1. You can create a single function prg with the same name as the function. VFP will then find it if the prg is in the search path or built in the the app or exe.

2. Create a multi function prg and in your form or your programs startup program (or any code that is called before the function is needed) put the line set library to myfunctions.prg

3. If you are using a DBC not free tables you can add procedures and functions to the dbc (see the modi proc command) and they will be available whenever the dbc is open.

 

If the function is only to be called from the one form, add the function to the form:

In form design mode, from menubar, select form|new method, and in the box, type in the name of the function, click add, then close.

Go to the form's code window. The new fuction will appear after all of the built-in methods. You can also see it in the Properties window.

In the code window, be sure to end your code with a "Return" statement, passing back whatever your function needs to, i.e.

RETURN nRetVal

You can code this just like any function/method. If you need to accept parameters, your first line needs to declare the params....




 
I would create a program call main.prg and make it the "Main" program in the project.

Just use it to setup the environment and then call the form and issue the READ EVENTS command.

Then put the function at the bottom of the PRG file ... after the return statement.

Then use that scenario for all your applications.

Don
dond@csrinc.com

 
You can have all the small small procedures under one '.prg' file (say MYPRGFILE) and set the procedure to that file by SET PROCEDURE TO MYPRGFILE (This you do in the main prg file or in the init event of the form).

If you are adding all this type of procedures at the end of your main prg, then you need not even set the SET PROCEDURE TO MYPRGFILE as the main prg by default will be searched by FoxPro.

Hope this helps you.





ramani :-9
(Subramanian.G)
FoxAcc
ramani_g@yahoo.com
 
Lots of useful things in this thread. Most of which I'd heard of before, but forgotten. :-(

So I downloaded the thread and hopefully will remember to read it again later. --Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top