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

FIND DATA TYPE IN VFP 6

Status
Not open for further replies.

mroth36

Programmer
Jul 21, 2005
27
HOW CAN YOU DETERMINE THE DATA TYPE OF A FIELD OR MEMORY VARIABLE (THE TYPE() FUNCTION IS NOT WORKING FOR ME)?
 

What do you mean TYPE() doesn't work for you?
Does it always fail or in some particular situations? What does it return? How do you use it? Do you include variable name in quotation marks?

In any case, you can try VARTYPE() function, it seems to be more versatile than TYPE().

Code:
VARTYPE() is similar to the TYPE() function, but VARTYPE() is faster and does not require quotation marks to enclose the expression for which the data type is returned. 

VARTYPE() returns “U” if you specify a variable that doesn’t exist.
 
Why is TYPE() not working for you?

Just to see it, use DISPLAY STRUCTURE or DISPLAY MEMORY.
However, programmatically you can use TYPE() or even VARTYPE(). Here's an example:
Code:
STORE 'Something' to cTemp
?TYPE('cTemp')  &&... returns 'C'
?VARTYPE(cTemp)  &&... returns 'C'

STORE DATE() TO cDate
?TYPE('cDate')  &&... returns 'D'
?VARTYPE(cDate)  &&... returns 'D'

Note that quotes are needed for TYPE() but will return the wrong value for VARTYPE()


-Dave Summers-
[cheers]
Even more Fox stuff at:
 
Check AFIELDS() function in HELP to see how to get FIELD type. It can't be used for variable.
As all above said you can use TYPE() or VARTYPE() to get he same info, but be careful, VARTYPE didn't works in any occasions. If you want to check a type of some property VARTYPE will raise an error if the property didn't exists:
Code:
? TYPE([_VFP.TestProp])  &&--> Returns "U" as it must be
? VARTYPE(_VFP.TestProp) &&--> Caboom :o))

Borislav Borissov
 
I AM SORRY, IT'S WORKING FINE!, THE BOOK DIDNT MENTION QUOTES, I HAD-THIS-FEELING-THAT-IT-WAS-SOMETHING-SIMPLE.
I APPRECIATE YOUR RESPONSE. THANK'S TO ALL!!!
 
Stella740pl, I consider TYPE() to be more versatile than VARTYPE(). TYPE() allows you to drill down an extra level, but the penalty is that it is slower so you don't want it inside code that loops a lot.

VARTYPE({varName})

TYPE("{varName or data}")... returns data type of variable or data

TYPE({varName}) ... returns data type of variable named inside varName

Example:
VarNum=1
VarChr="VarNum"
? TYPE("VarChr")
C
? TYPE(VarChr)
N
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top