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

How do I store variables within a procedure?

Status
Not open for further replies.

intel2000

MIS
Jan 22, 2003
25
US
Below is my procedure but when I execute:
APPEND FROM temp.dbf FOR compid="PSF" AND curdate=wdate

It does not know what wdate is!!!

Can anyone help?

Thanks,

Ross


*********************************************
Procedure getdate
STORE "N" TO correction
CLEAR
DO WHILE correction="N"
STORE " " TO wdate
@15,40 say "ENTER WRAPUP DATE(yymmdd):" get wdate function "!"
READ
STORE wdate TO wdate
@16,40 say "Is this date correct(Y/N):" get correction function "!" valid correction $ "YN"
READ
ENDDO
return
 
the line:

STORE wdate TO wdate
was put there for dumb testing purposes...


sorry

THanks,

Ross
 
If you are trying to initialize the wdate with a set value you can pass it into the procedure as a parameter.

Code:
DO myPROC with CTOD("01/01/1980")

PROCEDURE myPROC
PARAMETER tdDate
IF PCOUNT() > 0
   wdate = tdDate
ELSE 
   RETURN
ENDIF

* continue with your code




Jim Osieczonek
Delta Business Group, LLC
 
Hi Ross,

When Procedure getdate finishes all it's variables go out of scope. Including wdate. You could return it as a value from a Function though.

Regards,

Mike
 
Again, it depends what version of FoxPro Ross is using. If it's 2.6 or earlier version then all you need to do is to make sure that you call the procedure getdate before APPEND FROM command in your code. Otherwise Mike's answer stays valid.

Thanks
 
Below also works! (I declared the var public in the procedure)

PROCEDURE getdate
PUBLIC wdate
wdate = " "
STORE "N" TO correction
CLEAR
DO WHILE correction="N"
@15,40 SAY "ENTER WRAPUP DATE(yymmdd):" GET wdate FUNCTION "!"
READ
@16,40 SAY "Is this date correct(Y/N):" GET correction FUNCTION "!" VALID correction $ "YN"
READ
ENDDO
RETURN
 
Hi Ross,

@ SAY...GET??? What version are you using?

It's considered a better practice to use a custom form property rather than a public variable.

Regards,

Mike
 
I am using vfp 8.0.

I'm kind of new to fox... what is a custom form property? How and why should I use it?

Thanks,

Ross
 
Hi Ross,

With a form open in the Form Designer, there is a menu Form->New Property and Form->New Method. You can add your own properties and methods to the form. You use them by referencing them with thisform, ie. thisform.newProperty or thisform.newMethod(). They are automatically released when the form unloads. Using public variables places you at risk that you, or someone else, 6 months from now will reuse the same variable name and "break" your app.

If you don't use the Form Designer check addproperty() in the help.

Regards,

Mike
 
@ SAY/GET is realy very old history. They worked together with READ command, which is history too. Same with commands like DEFINE/ACTIVATE WINDOW.

Today object forms with object controls and READ EVENTS command are used.

I hope, you create the code from Project (New/Open Project).
In Project window set Documents/Forms list or set Classes list and use New.. (accessible through button or rightclick). Then you will see an empty form. Move controls from Form control toolbar (View,Toolbars..) to your form.

If you create a form from Documents/Forms list, your form definition will be saved in .scx file. DO FORM command then runs such form.

If you create a form from Classes list, choose Based on Form class. Your form is then the class in classlibrary (.vcx) and you can run it with:
oForm = NEWOBJECT( 'formname', 'c:\path\classlibrary.vcx' )
oForm.Show()
If form is modal, program halts inside the Show method and will continue when you close the form.
If form is modeless, add READ EVENTS command (and CLEAR EVENTS somewhere into the form closing code, f.e. to Form.Destroy).

Good idea is not to design forms and controls directly based on baseclasses (form, textbox,..), but add one (or more) level of classes (f.e. myform, mytextbox,..), and such classes/controls then use to design application forms.

In the beginning do nothing with the classes like myform, mytextbox. But later you will see, that if you change something there (properties, or you program some code into methods), you will change behaviour of whole your application (all forms) on single place.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top