Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Vartype: behavior
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00136852
Message ID:
00137541
Views:
46
>I read this when it came out, and then was surprised when I COULDN'T generate an error using VARTYPE, I just get 'U' as one might hope to. How did you get an error out of it?

VARTYPE() was designed to be a faster way of checking the variable type of an existing variable, property, or return value. Think of it like a custom VFP function, in which you are passing it a value that is resolved, just like foo(myvar). If myvar doesn't exist, you get a "U". You are actually passing myvar, evaluated, to VARTYPE(). VARTYPE() is 4 times faster than TYPE(), and it also returns an "X" for NULLs so you don't have to do a VARTYPE(o)=="O" AND NOT ISULL(o), just use VARTYPE(o)#"X", etc. The trick to VARTYPE() is that if you pass a memvar that doesn't exist, it returns a "U" with no error. If you try to calculate a value like VARTYPE(foo+foobar) and one of those variables doesn't exist, you will get a runtime error because the foo+foobar will be executed before VARTYPE() is called internally. TYPE() has one major use of VARTYPE(), and that is with use of table fields, since TYPE() returns the actually datatype (M, B, etc.) of the field and not the variant type at runtime as a variable would store it. Hopefully this makes sense and helps clarify when you want to use TYPE() vs. VARTYPE().
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform