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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What is a good Vfp substitute for IsArray()

Status
Not open for further replies.

justamistere

Programmer
Jul 25, 2002
67
US
In VFP 6, I haven't found any inherent IsArray() function like VB has. I am sending a @param1 to either a Procedure/Method, where I want to test to see if it is array or just a single memory variable.

I have something that may work, hopefully in all situations. I was wondering how others have achieved this common test.

Code:
*20*********************************************************
* Name:		IsArray()
* Author:	JXE 2004/10/25
* Description:	Determine if a variable is an array.
* Syntax:	llIsArray = IsArray(@txValue).
************************************************************
FUNCTION IsArray
LPARAMETERS	txMemVar
LOCAL	lcOLD_ErrorHandler, ;
	lnErrorNumber, ;
	llReturnValue

STORE	""	TO	lcOLD_ErrorHandler
STORE	0	TO	lnErrorNumber
STORE	.T.	TO	llReturnValue

lcOLD_ErrorHandler = ON("ERROR")
ON ERROR lnErrorNumber = GetErrorNumber(ERROR())
= ALEN(txMemVar, 1)

***---| "name" is not an array (Error 232)
IF lnErrorNumber = 232
	llReturnValue = .F.
ENDIF

ON ERROR &lcOLD_ErrorHandler
RETURN llReturnValue
************************************************************

*21*********************************************************
* Name:		GetErrorNumber()
* Author:	JXE 2004/10/25
* Description:	Returns the VFP error number returned by
*               the ERROR() function.
************************************************************
FUNCTION GetErrorNumber
LPARAMETER	tnErrorNumber
  LOCAL lnErrorNumber
  lnErrorNumber = tnErrorNumber
RETURN lnErrorNumber
************************************************************



 
Heya justamistere

You should be able to use the TYPE() function. It's what I use. Below is an sample prg.


Code:
CLEAR
LOCAL llIsArray,;
      lcTest

*-- Don't pass anything
m.llIsArray = IsArray()
IF m.llIsArray
   ?"#1 Array"
ELSE
   ?"#1 Not Array"
ENDIF  

m.lcTest = ""

*-- Pass text string
m.llIsArray = IsArray(m.lcTest)
IF m.llIsArray
   ?"#2 Array"
ELSE
   ?"#2 Not Array"
ENDIF  

*-- Pass Array
DIMENSION laTest[12,32]
m.llIsArray = IsArray( @laTest )
IF m.llIsArray
   ?"#3 Array"
ELSE
   ?"#3 Not Array"
ENDIF  

RETURN 


*--------------------------------------------------
*) Descript....: Display Parameter Value
*
*  Parameters..: 
*--------------------------------------------------
FUNCTION IsArray( tuValueToTest )
   LOCAL llIsArray

   *-- It's an array if we can see the "element"
   m.llIsArray = ( TYPE( "tuValueToTest[1,1]") <> "U" )

   RETURN m.llIsArray
ENDFUNC

HTH

Toodles,
Steve Dingle
D&S Business Solutions Ltd
 
And for the lurkers, this is all unneccesary in VFP 9.0. The new option on the TYPE() function will return "A" when it's an array!

Rick
 
Rick,

The new option on the TYPE() function will return "A" when it's an array!

Yes, I remember reading that somewhere. But, as with so many useful new features in 9.0, the developers don't appear to have passed the news to the guys who write the Help file.

Mike


Mike Lewis
Edinburgh, Scotland

My Visual Foxpro web site: My Crystal Reports web site:
 
And for the lurkers...
[wavey3] <waves to the lurkers>

boyd.gif

 
In VFP8 I find it more reliable to use:

Code:
IF TYPE('ALEN(myarray,1)')="N"
   *--Is an array
ELSE
   *--Is not an array
ENDIF
 
Mike,
It's in the updated help file in the TYPE() topic - it was released about a week ago. Download it at:

Note: This does document a few features NOT available in the public beta, but will be in the final release, and it still needs additional "fixes" itself. Also, you can get and read this help file even if you don't install VFP 9.0 (beta). That way you can check out the new features by just reading about them. (You may be inspired then to install the public beta to try some of them out!)

Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top