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

passing parameters 1

Status
Not open for further replies.

Samalia

Technical User
Jun 7, 2005
46
CA
Im trying to pass a variable between two forms with a parameter. I want to be able to double click on a field and go to another form with it looking at the same customer number. In my double click event I have

LParameter tncustomernumber
SELECT customertable
DO FORM customerform with tncustomernumber

and in the init of the other for im calling is

LPARAMETER tncustomernumber
SELECT customertable
Do Case
With tncustomernumber.type = O
Do Case
Case tncustomernumber = .t.
LOCATE FOR customertable.customernumber = tncustomernumber
thisform.txtCustomernumber.Value = tncustomernumber
thisform.refresh
EndCase
EndWith
With tncustomernumber.type = L
Do Case
Case !tncustomernumber = .t.
GO RECNO()
thisform.refresh
EndCase
EndWith
EndCase

so that i can call it from another form or on its own. why isnt the parameter passing?
 
So, you've debugged and found that tnCustomerNumber has a value just before you pass it to your customerform? And, that tncustomernumber has no value (.F.) in the init event of the customerform? The only reasons I can think of that this could happen (if the above two questions check out) is that you have code above the lparameters line or the form in question is actually a formset, which case the parameter would be sent to the Load event instead of the init.

boyd.gif

SweetPotato Software Website
My Blog
 
if i put the code in the load event of the form, there is and error message saying "No PARAMETER statement is found.
 
Samalia,

You may want to come up to speed with Visual FoxPro's debugger so you can ascertain what the value of tnCustomerNumer is in both forms. For starters you can put the following command in the code of your first form right below the lparameters statement...

Set Step On

...this will bring up the debugger for you when you run your project inside of Visual FoxPro. Then you can step through the code using the F8 function key. In the debugger make sure you have the Locals Window open so you can watch the value of your parameter.

Since moving the code to the Load event blew up, this means that you are indeed using just a regular form. A look in the properties of your form to see what class it was based on would have been a more efficient way to check this however.

I really think you will find out what is going on rather quickly if you can start using the debugger. Plus, it will help you in the future with your coding efforts and diagnosing problems.

Don't forget to remove the Set Step On from your code once you've ascertained the problem. It's always good to clean up after yourself, and this will throw an error "Feature Not Available" in the compiled application in early versions of VFP.

boyd.gif

SweetPotato Software Website
My Blog
 

Samalia,

You were right the first time. The code should be in the Init, not the Load.

More importantly, what exactly is tnCustomerNumber? It looks like a simple number, but you are treating it as an object. Did you mean to just pass the number, or do you want to pass an object reference to the entire textbox? And
why is it a parameter of the first form?

Also, your WITH / ENDWITH statement looks a bit strange. The keyword WITH should be followed by an object refernce, not an expression.

I would have thought you need something like this:

In the DblClick of the textbox:

DO FORM CustomerForm WITH THIS.Value

In the Init of CustomerForm

LPARAMETER tnCustomerNumber
WAIT WINDOW TRANSFORM(tnCustomerNumber)
* Above line is just to check it was received OK. Can be
* removed when it is working.

* -- code here process the customer number in some way


Perhaps you could get the above code working, and then we can look at what comes nexr.

Mike




__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
Trying that new code brings me up a wait window displaying .F., then an error message of operator/operand mismatch. I look in the debugger and the tncustomer is logical and false. But if i set step on in the double click event, and I look to see what the tncustomernumber is in there, it has the proper value.
Here's my new code:
Double Click Event;
LParameter tncustomernumber
GOTO TOP IN customertable
LOCATE FOR customertable.customernumber = thisform.txtcustomernumber.Value

IF !FOUND()
MESSAGEBOX("Customer does not exist.", 0, "Customer Finder")
ENDIF

IF FOUND()
tncustomernumber = this.value
SET STEP ON
DO FORM customerform WITH tncustomernumber
ENDIF

Init Event;
LPARAMETER tncustomernumber
WAIT WINDOW TRANSFORM(tncustomernumber)
SELECT customertable
LOCATE FOR customertable.customernumber = tncustomernumber
thisform.txtcustomernumber.value = tncustomernumber
thisform.refresh
 

Samalia,

If you'd care to glance back at my post, you will see that this is the line that is causing the problem:

DO FORM customerform WITH tncustomernumber

You need to change tncustomernumber to THIS.Value.

Also, take out the LPARAMETER statement at the start of the DblClick event.

The root of the problem is that DblClick does not receive a parameter. But the LPARAMETER statement is declaring the variable, tnCustomerNumber, and giving it a value of .F. It is that value that is being passed to the form. As far as I can see, you want to be passing the actual number that the user typed into the textbox. THIS.Value will give that to you.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
Hi Samalia,

From the posted code, I can't see why the parameter isn't showing up in the called form, however, there is no need to pass it.

In the double click event of the calling form

LParameter tncustomernumber

* No need for GOTO TOP - Locate will do that automatically
*GOTO TOP IN customertable

LOCATE FOR customertable.customernumber = thisform.txtcustomernumber.Value

IF FOUND()
DO FORM customerform
ELSE
MESSAGEBOX("Customer does not exist.", 0, "Customer Finder")
ENDIF

and you will open the CustomerForm with the record you want already selected.

Regards,
Jim
 
Hi Mike,

Good catch on the lparameter as opposed to This.Value. I missed that completely.

Regards,
Jim
 
is the only way to share a data session with the calling form making them a formset?
 
Hi Samalia,

No. If you call a form with its datasession set to 1, it will use the datasession of the calling form.

Regards,
Jim
 
ok, so now my form will pass the parameter, but if i try to run the second form on its on, it gives me an operator operand mismatch, if i press ignore it goes to the first record. my code is this

LPARAMETER tnSerialNumber
SELECT boardstable
LOCATE FOR boardstable.boardnumber = tnserialnumber
thisform.Refresh

if i try to use an if statement to only get it to process the parameter if its there, when i run it from another form, it still says tnserialnumber is not an object
 
Hi Samalia,

Try DO FORM myForm WITH myParameter TO myVariable.

Create a custom property myProperty in myForm.

In the Init of myForm:
LPARAMETER InputVariable
this.myProperty = InputVariable

Do whatever processing leaving the result in this.myProperty

In the Unload of myForm:
RETURN this.myProperty

The reason you have to do it this way is that unless the variable is declared public in the init it is destroyed when Init finishes.

Regards,

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top