How to check if an Array exists?

Select * from myTable where isnull(myTable.keyField) = .f. into array myArray
if alen(myArray) > 0
** Loop through array and Do processing
end if

In a situation where records selected by the query are 0 then the array is not created and thus the next statement gives an error.

How can I check if myArray exists before doing any further processing?

[401 byte] By [FoxProg9] at [2008-2-22]
# 1
in VFP9, TYPE("theVar",1) returns "A" if theVar is an array. In earlier versions, you can use TYPE("theVar[1]"):
varIsArray = TYPE("theVar[1]") # "U"
EricdenDoop at 2007-9-8 > top of Msdn Tech,Visual FoxPro,Visual FoxPro General...
# 2
local array myArray[1]
select ... into array myArray
if _Tally > 0
* do processing
CetinBasoz at 2007-9-8 > top of Msdn Tech,Visual FoxPro,Visual FoxPro General...
# 3

I ended up using the Type(), but it is nice to know that there is something like _TALLY.

Thanks Eric and CetinBason for your help.

FoxProg9 at 2007-9-8 > top of Msdn Tech,Visual FoxPro,Visual FoxPro General...
# 4

Not for discussion but I wanted to warn you about checking with type().

Type() cannot tell exactly if it's an array (unless used with extra parameter in VFP9).
1) Suppose you have an object which supports collection:

type('oObj[1]') would unlikely to be 'U'

2) You've a prg or procedure named the same way which accepts a number as parameter:

type('myProcedure[1]') would again not be 'U'

Of course you could work around both by making sure you don't have such name collisons.
To check if something is array then you need to check it with a function that operates on arrays. ie:

if type('alen(arrMyArray)') = 'N'

However _Tally is not 100% trustable either. Either with type() or _tally you might get a result as if you had something usefull returned. ie: VFP9 engine returns at least 1 record when you use max()).

LOCAL ARRAY
arrMax[1]

SELECT MAX(maxordamt) FROM customer ;
WHERE cust_id == 'NOTEXISTING' INTO ARRAY arrMax

? _Tally, ;
TYPE('alen(arrMax)'), TYPE('arrMax[1]'), ;
_Tally > 0 and !ISNULL(arrMax[1])

CetinBasoz at 2007-9-8 > top of Msdn Tech,Visual FoxPro,Visual FoxPro General...
# 5
Thanks for the indepth explanation CetinBasoz.
I see your point and I think I am going to try to incorporate type('alen(arrMyArray)') = 'N' in my code.
FoxProg9 at 2007-9-8 > top of Msdn Tech,Visual FoxPro,Visual FoxPro General...