Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How can I check to see if an array has been created?
Message
From
12/10/2001 04:41:55
 
 
To
11/10/2001 23:57:39
Peter Brama
West Pointe Enterprises
Detroit, Michigan, United States
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00567404
Message ID:
00567446
Views:
14
Hi!

You can use type() function to see if variable already exists. If variable exists, use type("MyArray[1]") == "U" to see if it is array.

However, indeed, type() function works slowly. In usual case in some kind of the algorithm it is much better to add a logical flag that will become .T. as soon as array defined. Example:


local llArrayCreated
....
if llArrayCreated AND len(MyArray,1)=nSomeValue && note that len() will not be evaluated when
&& llArrayCreated is .F. - VFP do not continue to calculate logical expression
&& when its result is alredy determined for sure. This could be not true for
&& some other programming languages, for example, for VB
...
dimension MyArray(...)
llArrayCreated = .T.
...
endif


Above is much more clear and more natural way of programming for all programming languages.

HTH.

>I am using an array in a program and on the first pass through a method, it is possible that the array hasn't been created yet (the routine is primarily for subsequent passes). Of course I get an error when I do a ALEN on the non-existant array. I have tried various commands to see if I can check for it but they all generate an error. Is there a command that can tell if an array (or variable of anytype), exists without generating an error?
Vlad Grynchyshyn, Project Manager, MCP
vgryn@yahoo.com
ICQ #10709245
The professional level of programmer could be determined by level of stupidity of his/her bugs

It is not appropriate to say that question is "foolish". There could be only foolish answers. Everybody passed period of time when knows nothing about something.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform