INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Usefull Functions & Procedures

How to check for an array's existance. by myearwood
Posted: 29 Oct 07

In my Foxpro Advisor article (subscription required): http://my.advisor.com/doc/17117

I argued that this line of code:

CODE

IF TYPE("ALEN(m.SomeVariable")
is not as readable, maintainable or extendable as:

CODE

IF X2IsArray(@m.SomeVariable)
Remember, copying code is not code reuse! ;)

The following code originated with me and was donated to the FoxPro community by Russ Swall President of VisionPace in memory of Drew Speedie.

CODE

*
*  X2IsArray.PRG
*  RETURNs a logical value indicating whether the
*  variable PASSED BY REFERENCE or the passed Object.Property
*  is an array.
*
*  Copyright (c) 2004-2005 Visionpace   All Rights Reserved
*                17501 East 40 Hwy., Suite 218
*                Independence, MO 64055
*                816-350-7900
*                http://www.visionpace.com
*                http://vmpdiscussion.visionpace.com
*  Author:  Drew Speedie
*           Special thanks to Mike Yearwood and Chris Bohling
*
*  USAGE
*  =====================================
*  IF X2IsArray(@m.SomeVariable)
*    ...
*  ENDIF
*  IF X2IsArray(SomeObject,"SomeProperty")
*    ...
*  ENDIF
*
*
*  lParameters
*   tuVariable (R) Memory variable to be checked,
*                    passed here BY REFERENCE
*                    -OR-
*                  Object whose tcProperty is to be
*                    checked
*   tcProperty (O) If tuVariable is passed as an object
*                    reference, this parameter is REQUIRED,
*                    and indicates the property of the
*                    tuVariable object that is checked for
*                    being an array
*                  If tuVariable is passed as a memory
*                    variable, DO NOT PASS THIS PARAMETER,
*                    or this routine will RETURN .F.
*
LPARAMETERS tuVariable, tcProperty

LOCAL llRetVal

DO CASE
  ******************************************************
  CASE PCOUNT() = 1 AND NOT VARTYPE(m.tuVariable) = "O"
  ******************************************************
    llRetVal = TYPE("ALEN(m.tuVariable)") = "N"
  ******************************************************
  CASE PCOUNT() = 1 AND TYPE("ALEN(m.tuVariable)") = "N"
  ******************************************************
    llRetVal = .t.
  ******************************************************
  CASE VARTYPE(m.tuVariable) = "O" ;
       AND VARTYPE(m.tcProperty) = "C" ;
       AND NOT EMPTY(m.tcProperty)
  ******************************************************
    llRetVal = TYPE("ALEN(m.tuVariable." + m.tcProperty + ")") = "N"
  ******************************************************
  OTHERWISE
  ******************************************************
    *
    *  you apparently haven't passed the parameters
    *  properly -- we could have RETURNed .NULL. here,
    *  but then every time you call X2IsArray(), you
    *  would have to check for .NULL, .T., and .F.
    *  rather than just .T. or .F., so it's up to you
    *  to pass the parameters correctly
    *    Roses are red
    *    Violets are blue
    *    To pass parms correctly
    *    Is all up to you
    *
    llRetVal = .f.
ENDCASE

RETURN m.llRetVal

Back to Microsoft: Visual FoxPro FAQ Index
Back to Microsoft: Visual FoxPro Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close