Reply to comment

Is variable or property an array?

When validating a function, procedure or method parameters, it's sometimes necessary to determine if passed parameter is an array. Until VFP 9.0 there was no obvious way to do that.

In VFP 9.0 the TYPE() function accepts additional second parameter 1, to determine if passed expression is an array, a collection or neither. In previous VFP version we can use the TYPE() function in combination with ALEN() function.

This is sample code. Add error handling and adjust to your requirements as necessary.

* VFP 9.0
IF TYPE("SomevariableOrProperty",1) = "A"
  * It's array   
ENDIF
 
* VFP 8.0 and earlier  
IF TYPE("ALEN(SomevariableOrProperty)")) = "N"
  * It's array
ENDIF 

A check TYPE("SomevariableOrProperty[1]") = "N" doesn't work for VFP intrinsic properties. It incorrectly returns 'N' for all of them.

loForm = CREATEOBJECT("Form")
? TYPE("loForm.Top[1]")            && Returns N
 

Reply

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <java>, <powershell>, <tsql>, <visualfoxpro>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.