Microsoft KB Archive/139863

= How to Determine the Variable Type =

Article ID: 139863

Article Last Modified on 2/10/2000

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition

-



This article was previously published under Q139863



SUMMARY
When using the Visual FoxPro TYPE function, you must ensure that the expression passed to the function is always be of the character type. You can use a user-defined function (UDF) to determine the type of a variable without trying to convert the variable to a character string. This article shows you how to do it.



Step-by-Step Example
  Open a program file, and type the following function into it: FUNCTION ALLTYPE *   *  Purpose:  Determine the data type of a variable * Syntax:   m.cNewValue = ALLTYPE() * Parms:    xxx (Can be Character, Numeric, Date, or Logical) *           The variable for which the type is to be determined. * Return:   lcType:  C for Character *                    N for Numeric *                    D for Date *                    L for Logical * Example:  lcTheType=ALLTYPE(Variable) *   PARAMETER xxx local llType,lcType lcTemperror=ON('ERROR') ON ERROR llType=.f.   llType=.T.    xxx=xxx+" " IF llType lcType="C" ENDIF llType=.T.   xxx=!xxx IF llType lcType="L" ENDIF llType=.T.   xxx=xxx+1 IF llType lcType="N" ENDIF llType=.T.   xxx=MONTH(xxx) IF llType lcType="D" ENDIF ON ERROR &lcTemperror RETURN lcType  The value returned is N.

The TYPE function may be used to obtain the same result if the variable is placed enclosed in quotation marks. For example, the following will also return N:  ? TYPE('x')

Additional query words: VFoxWin

Keywords: kbcode KB139863

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.