Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Mike Yearwood
  Where is Mike Yearwood?
 Toronto
 Canada
 Mike Yearwood
 To: Samir H.
  Where is Samir H.?
 Yogyakarta
 Indonesia
 Samir H.
 Tags
Subject: RE: Passing arrays to procedures
Thread ID: 268401 Message ID: 268818 # Views: 27 # Ratings: 0
Version: Visual FoxPro 9 Category: General VFP Topics
Date: Wednesday, July 14, 2010 7:13:43 PM         
   


> > Samir
> >
> > Just use http://fox.wikis.com/wc.dll?Wiki~X2ISARRAY
> >
> > In VFP itself they altered TYPE() so it could accept an extra parameter, but that would mean searching every line of code for the TYPE(). Vartype was added because TYPE() is slower.
> >
> > Now, I know a UDF may seem like overkill to some, but the point is to take something complex, error prone, mysterious and unreadable and make it reliable, maintainable, extendable and a UDF does that.
> >
> >
>
> Hi Mike
> Thanks for the article. Good to know about the TYPE() features...
>
> I want to ask: why is the second case here?
> It looks like every call is either caught by case 1 or case 3. Unless wrong arguments are passed, may be.

That is a good question. The function was modified after I gave it to Drew to add support for object array properties. A good function handles the complexities without our having to understand it all. I'll let you know when I can check.


>
>
>   CASE PCOUNT() = 1 AND NOT VARTYPE(m.tuVariable) = "O"
>     * Not an object: check and return...
>     llRetVal = TYPE("ALEN(m.tuVariable)") = "N"
>   CASE PCOUNT() = 1 AND TYPE("ALEN(m.tuVariable)") = "N"    
>     llRetVal = .t.   && when can such a case happen?
>   CASE VARTYPE(m.tuVariable) = "O" ;
>        AND VARTYPE(m.tcProperty) = "C" ;
>        AND NOT EMPTY(m.tcProperty)
>     llRetVal = TYPE("ALEN(m.tuVariable." + m.tcProperty + ")") = "N"
>   OTHERWISE

>
> And also, how would such a function help if we follow good programming by declaring EVERY variable, or array.

When you call a function that is expecting an array, you need to know if it is an array or not. Each function should not assume the programmer called it correctly.

> I'm now speaking about a case like Tony brought in this part of the thread, where he would like to know if the array has been filled by something (something other than the declaration, which fills every array with .F.)
> The testings we spoke about are still necessary (vartype() etc.)
>
> > There is another problem I run into often and that's how to tell if an array is empty. Since the lowest subscript is 1 and not 0 this is ambiguous
>
> > dimen myarray(1)
> > myarray(1) = 0
> > ?empty(myarray) && true (This is not correct since I just filled the array with 0!!)
>
>
LOCAL ARRAY aArray[1]
> ?x2IsArray(@aArray)	&& .T.
> ?VARTYPE(aArray)	&& "L"
> 
> LOCAL ARRAY aArray[1]
> aArray[1]="A"
> ?x2IsArray(@aArray)	&& .T.
> ?VARTYPE(aArray[1])	&& "C"

>
>
> Regards
> Samir



Mike Yearwood
Microsoft MVP Visual FoxPro 2008, 2009
We have enough youth. We need a fountain of smart!
There may be many ways to skin a cat, but there are very few right ways to do it.

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