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

Problem Passing Parameters

Status
Not open for further replies.

Maxlore

IS-IT--Management
Mar 9, 2011
12
US
Can someone explain to me what I am do wrong ??
I have in "Form A" a visual class that calls "Form B" passing
variables that is set by the users selections with ,,

DO FORM frmName WITH parm1,parm2,parm3, ... so on

In Form B Init Method

Parmeters parm1,parm2,parm3, ... so on

Form A Modeless
Form B is Modal
voChkBoxes is the Visual Class in which I get the user selections
and set all the variables

Problems is this ,, all variables are set and correct at the last
line of code before the DO FORM statement, as soon as the DO FORM
is executed the parameters are set to the Original Values...
Can someone tell me what I have forgotten ... And please excuse
my ignorance,, If my thinking is wrong please advise me...!!

Max

 
So is the do form not in the same method as the variables are set?
And what do you mean by original values?

Have a read on variable scopes in the vfp help, perhaps.

It's hard to give a more specific advice from the description you give.

Bye, Olaf.
 
I am sorry for the description i gave,,,To answer your question
Yes, the Do Form is executed from the same Method,,all parameters and Do Form are executed from the Visual Class I created,,in this case a chkbox class,,,Thanks for trying to help Olaf..And I have read on variables in the help,,but it has been a long time since i
programed in vfp..Sorry again for my ignorance..

Max
 
I'm betting the problem is that the called form's INIT method ends and the variables go out of scope (and are released).

In the INIT method, right after the PARAMETERS statement, you need to store the values received as parameters into form properties or those values won't be usable outside the init method.
 
Dan ,,I do store the params passed to the called form properties
after the Parameters statement,,,in debug the parameters are reset to the previous values,,meaning all variables that i gathered and set from the user selections revert to the previous values. And yes they do seem to go out of scope,,,I am probably do a sorry job explaining this problem ,, and i am sorry for that..trying to get a grip back on all this after be very ill for a long time..

I'll try to explain this better,,I hope anyway :)..

Form A has a CmdGroup Class that i created that calls up the ChkBox class ,, after the user selects all chkboxes that they require the
Do Form B is executed with
DO FORM frmName WITH parm1,parm2,parm3, ... so on

At that point is when all the variables are reset
What am i doing wrong ???
I have read/researched passing variables and found no answer yet..
Any further help would be wonderful..

Max
 
Max,

I'm not sure I completely understand the problem. But my first reaction would be to check that the all the parameters are declared as locals, both in the caller and the Init of the called form.

In other words, you should have this line in your calling method:

LOCALS parm1,parm2,parm3

And this one in the Init of the called form:

LPARAMETERS parm1,parm2,parm3

(note the L in front of PARAMETERS).

This is especially important if the variables in question have the same names in both the caller and the called - as would be the case if they were actually called param1, etc.

I'm not saying that's the root of the problem, but it could be contributing to it.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
So you're saying the value received in parm1 is different from the value sent? I cannot think of any way that might happen. The act of passing a parameter DOES NOT change that parameter's value.

When you say they're "reset", what does that mean? Are they all set to logical .f.? "Reset" isn't a concept known to most Foxpro developers so it may not mean what YOU think it does when you use the term. :)
 
Maybe this will help
Form A CmdGroup Class (8 buttons)
cmdbutt2 Click event is THISFORM.vlchkboxes1.Visible = .T.

vlchkboxes1 Class has 15 chkboxes
In the Click Event/and or InterActiveChange Event tried both ways
I set a variable to true parm1 = .T. if clicked. (which is not the best way to do this but trying to see whats going on)
Then user submits with a cmdbutt that is in the vlchkboxes1 Class

DO FORM frmName WITH parm1,parm2,parm3, ... so on

Like I said all params or ok and correct immediately before the
DO FORM statement,,,,immediately after they seem to lose scope
not being passed from what i can see...I know it has to be me doing something wrong ,, just don't know what yet..
I have tried with a simple 1 chkbox in a class i created just to debug and still have the same problem..

In it all i did was in the click event of the chkbox
trythis = .T.
DO FORM frmName WITH trythis
Same Problem

Max



 
I want to thank all of you for the help...Mikes Locals and LPARAMETERS seems to corrected the problem.. I will have to research why the PARAMETERS statement did not work as LPARMETERS
did...But that is for a little latter...again thank all of you guys
very much....

Max
 
You say "all variables that i gathered and set from the user selections revert to the previous values" So how do you gather user selections into variables?

One problem you have with DO FORM WITH is, that parameters are passed by reference, like described in the more general DO COMMAND in the WITH clause section.

That means all influences of formb on the parameters are done to the passed in variables.

Have a form (nonmodal) with the following init() code
Code:
lparameters tparam1
tparam1=tparam1+1

Call the form by
Code:
param1=1
do form formx with param1
? param1

a 2 will be printed. you might have the same effect with your variables. If you want to pass variables by value put them in paranthesis in the call, eg DO FORM formx WITH (param1) and you pass the value only.

Bye, Olaf.
 
I will have to research why the PARAMETERS statement did not work as LPARMETERS

It's because LPARAMETERS gives the received values a local scope (local to the Init, in this case). That means that VFP treats them as separate entities from the variables with the same names in the calling method.

You say you will research it later. I suggest that you don't postpone it for too long. The whole question of scope (local, private, public) is fundamental to programming (not just VFP), as is the distinction between passing parameters by reference and by value. You really need to understand those concepts before going much further.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Thank you all very much ,,, !and thanks much Mike for the info,,
I didn't mean i was going to postpone it long ,,just wasn't going to do it right at that moment,, ;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top