Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Christian Tabligan
  Where is Christian Tabligan?
 Bacolod City, Neg. Occ.
 Philippines
 Christian Tabligan
 To: Samir H.
  Where is Samir H.?
 Yogyakarta
 Indonesia
 Samir H.
 Tags
Subject: RE: Passing arrays to procedures
Thread ID: 268401 Message ID: 268702 # Views: 32 # Ratings: 0
Version: Visual FoxPro 9 Category: General VFP Topics
Date: Wednesday, July 14, 2010 5:48:51 AM         
   


> >
> > Hope this help.
> >
> > Basic Sample:
> >
> >
> > * Calling and Passing Array By Reference.
> > SET DEFA TO CURDIR()
> > SET PROCEDURE TO "PassingArray.prg"
> > LOCAL ARRAY aWord[2]
> > aWord[1] = "Hello "
> > aWord[2] = "World"
> > Messagebox(PassingArray(@aWord))
> > 
> > * Test Function
> > FUNCTION PassingArray()
> > LPARAMETER ARRAY Greeting[2]
> > RETURN Greeting[1] + Greeting[2]
> > ENDFUNC
> > 

> >
> > Sample Project:
> >
> > https://www.foxite.com/uploads/4db97f41-6bde-4022-8511-3aa949337e86.rar
> >
> > Best Regards,
> >
> > CriZ (,")
> >
> > "Happiness is real when shared."
>
> Hi Chris
> Without the EXTERNAL ARRAY and with LPARAMETER ARRAY in the function (I didn't know you can add ARRAY to LPAR!), is there an error when compiling? I didn't test.
>
> Regards
> Samir


In vfp6, nope Samir. I just specified it as an "ARRAY" so that i will know that it is an array. What important most is you pass an array as reference, otherwise, if you pass it by value, only the first element will be thrown in the parameter.

ex #1.

LOCAL ARRAY aWord[2]
aWord[1] = "Hello "
aWord[2] = "World"
do PassingArray with (aWord)

**********************************
PassingArray.prg
**********************************
LPARAMETER Greeting
?Greeting && no error   
?Greeting[1] && with error
**********************************  
ex. #2

LOCAL ARRAY aWord[2] 
aWord[1] = "Hello "
aWord[2] = "World"
do PassingArray with aWord && Pass array variable

**********************************
PassingArray.prg
**********************************
LPARAMETER Greeting[2]   && put array scope in the parameter
?Greeting[1]+Greeting[2] && no error
**********************************  

ex. #3

SET DEFA TO CURDIR()
SET PROCEDURE TO "PassingArray.prg"
LOCAL ARRAY aWord[2]
aWord[1] = "Hello "
aWord[2] = "World"
PassingByValueArray(aWord) && with error
PassingByValueArray(aWord[1]) && noerror
PassingByReferenceArray(@aWord) && no error
**********************************
PassingArray.prg
**********************************
FUNCTION PassingByReferenceArray()
LPARAMETER Greeting[2] 
RETURN Greeting[1] + Greeting[2] 
ENDFUNC

FUNCTION PassingByValueArray()
LPARAMETER Greeting
RETURN Greeting
ENDFUNC
**********************************  

ex #4
SET PROCEDURE TO "PassingArray.prg"
DIMENSION aWord[2,2]
aWord[1,1] = "Hello "
aWord[1,2] = "World"

?PassingArray(@aWord) && "Hello World"
?aWord[1,1] + aWord[1,2] && "Hello World"
?PassingArrayClone(@aWord) && "Nice! World"
?aWord[1,1] + aWord[1,2] && "Hello World"
?PassingArrayNoCloning(@aWord) && "Nice! World"
?aWord[1,1] + aWord[1,2] && "Nice! World" The original variable changed
**********************************
PassingArray.prg
**********************************
FUNCTION PassingArray()
LPARAMETER Greeting[2,2] && Again! Put the scope!
&&LPARAMETER Greeting && without scope! No Error
LOCAL laGreet[2,2]

&& This will reserve the original value of the array parameter
ACOPY(Greeting, laGreet) && Array Cloning.

laGreet[1,1] = "Nice! "
RETURN Greeting[1,1]+Greeting[1,2] && No Error
ENDFUNC

FUNCTION PassingArrayClone()
LPARAMETER Greeting[2,2] && Again! Put the scope!
&&LPARAMETER Greeting && without scope! No Error
LOCAL laGreet[2,2]

&& This will reserve the original value of the array parameter
ACOPY(Greeting, laGreet) && Array Cloning.

laGreet[1,1] = "Nice! "
RETURN laGreet[1,1]+laGreet[1,2] && No Error
ENDFUNC

FUNCTION PassingArrayNoCloning()
LPARAMETER Greeting[2,2] && Again! Put the scope!
&&LPARAMETER Greeting && without scope! No Error

Greeting[1,1] = "Nice! "

RETURN Greeting[1,1]+Greeting[1,2] && No Error
ENDFUNC
**********************************  


Best Regards,

CriZ (,")

"Happiness is real when shared."

ENTIRE THREAD

Passing arrays to procedures Posted by Tony Vignone @ 7/11/2010 6:46:56 PM
RE: Passing arrays to procedures Posted by Samir H. @ 7/11/2010 7:15:34 PM
RE: Passing arrays to procedures Posted by Tony Vignone @ 7/12/2010 6:52:53 PM
RE: Passing arrays to procedures Posted by Borislav Borissov @ 7/11/2010 7:19:17 PM
RE: Passing arrays to procedures Posted by Tony Vignone @ 7/12/2010 6:51:23 PM
RE: Passing arrays to procedures Posted by Mike Yearwood @ 7/13/2010 3:38:03 PM
RE: Passing arrays to procedures Posted by Tony Vignone @ 7/14/2010 6:39:43 PM
RE: Passing arrays to procedures Posted by Anil Sharma @ 7/11/2010 7:31:36 PM
RE: Passing arrays to procedures Posted by Tony Vignone @ 7/12/2010 6:55:23 PM
RE: Passing arrays to procedures Posted by Eduard @ 7/11/2010 10:34:31 PM
RE: Passing arrays to procedures Posted by Tony Vignone @ 7/12/2010 7:02:24 PM
RE: Passing arrays to procedures Posted by Samir H. @ 7/12/2010 7:28:19 PM
RE: Passing arrays to procedures Posted by Tony Vignone @ 7/13/2010 3:08:33 AM
RE: Passing arrays to procedures Posted by Samir H. @ 7/13/2010 3:48:58 AM
RE: Passing arrays to procedures Posted by Tony Vignone @ 7/13/2010 4:33:38 AM
RE: Passing arrays to procedures Posted by Tamar Granor @ 7/12/2010 10:48:02 PM
RE: Passing arrays to procedures Posted by Tony Vignone @ 7/13/2010 3:07:39 AM
RE: Passing arrays to procedures Posted by Koen Piller @ 7/12/2010 11:37:18 PM
RE: Passing arrays to procedures Posted by Tony Vignone @ 7/13/2010 3:02:01 AM
RE: Passing arrays to procedures Posted by Koen Piller @ 7/13/2010 4:07:34 PM
RE: Passing arrays to procedures Posted by Samir H. @ 7/13/2010 5:56:25 PM
RE: Passing arrays to procedures Posted by Koen Piller @ 7/13/2010 8:43:23 PM
RE: Passing arrays to procedures Posted by Mike Yearwood @ 7/13/2010 10:36:16 PM
RE: Passing arrays to procedures Posted by Samir H. @ 7/14/2010 4:42:58 AM
RE: Passing arrays to procedures Posted by Mike Yearwood @ 7/14/2010 5:57:12 AM
RE: Passing arrays to procedures Posted by Samir H. @ 7/14/2010 7:22:33 AM
RE: Passing arrays to procedures Posted by Mike Yearwood @ 7/14/2010 7:13:43 PM
RE: Passing arrays to procedures Posted by Koen Piller @ 7/14/2010 10:21:59 AM
RE: Passing arrays to procedures Posted by Tony Vignone @ 7/14/2010 6:59:18 PM
RE: Passing arrays to procedures Posted by tushar @ 7/13/2010 6:02:24 AM
RE: Passing arrays to procedures Posted by Tony Vignone @ 7/14/2010 7:00:41 PM
RE: Passing arrays to procedures Posted by Mike Yearwood @ 7/13/2010 3:39:32 PM
RE: Passing arrays to procedures Posted by Christian Tabligan @ 7/14/2010 4:46:09 AM
RE: Passing arrays to procedures Posted by Samir H. @ 7/14/2010 4:54:22 AM
RE: Passing arrays to procedures Posted by Christian Tabligan @ 7/14/2010 5:48:51 AM
RE: Passing arrays to procedures Posted by Tony Vignone @ 7/15/2010 3:06:02 AM