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!

Passign array to a method

Status
Not open for further replies.

billyng

Programmer
Dec 7, 2004
25
US
Hi folks,

I am trying to pass an array to a user define method with the following code

In the command button's click event

SELECT firstname, lastname ;
FROM users ;
WHERE id=123 ;
INTO ARRAY aUser
THISFORM.runautofill(@aUser)

In the form's runautofile method

LPARAMETERS aAutoFill

THISFORM.firstname.Value = ALLTRIM(aAutoFill(1,1))
THISFORM.lastname.Value = ALLTRIM(aAutoFill(1,2))

It works fine when I run the form, but it gets the error,
Unknown AAUTOFILL - Undefined, when I build it. Would anyone please tell me why, thanks!

Billy

 
Billy,

I suspect the parameter name in RunAutoFill needs to be aUser not aAutoFill.

Hope that helps,

Stewart
PS If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Use

EXTERNAL ARRAY aAutoFill

command as a 2-nd command (if first is LPARAMETERS).
 
Hey, it works. Thanks! By the way, how come I don't nned to use EXTERNAL ARRAY in a function or procedure for passing array? The compiler only complains it when it is in a form's method.
 
The compiler shouldn't be the one complaining: The Project Builder will complain because it is doing its best to make sure all functions are accounted for.

I would guess the reason your functions don't generate this issue is that they are called from within the same PRG that declares the array, and the arrays may be of the same name, as Stewart suggests.

- Bill

Get the best answers to your questions -- See FAQ481-4875.
 
Hi Billy,

How should foxpro know, that aAutoFill(1,1) is the element (1,1) of an array instead of the call of a function? So it complains about this with "Unknown AAUTOFILL - Undefined".

To make it more concrete: COMPILE ...prg won't tell you this, as it is compilable but BUILD will complain. Even if it's all in a single PRG making up the whole project, it'll complain but create a running EXE, it's really a warning.

I'd suggest using aAutofill[1,1], that'll not make it defined, but it makes it more clear.

Bye, Olaf.
 
Good point, I always mix up () with []. Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top