VarChangeType Procedure |
Version 5 |
Convert the value and type of the variant to the specified type.
[ lStatus = ] VarChangeType (pvDst, envtType [, vSrc])
The VarChangeType procedure syntax has the following parts:
Name |
Type |
Description |
lStatus |
Long |
Returned status (Windows SCODE), negative for error |
pvDst |
Var Variant |
A Variant, destination. Also source if vSrc is not given. |
envtType |
Val enumAVarType |
Variant type desired. |
vSrc |
Val Variant |
Optional. A Variant, source if given. |
The function can be used to convert a Variant to a specific data type. Data value is maintained if compatible; the function handles coercions between the fundamental types (including numeric-to-string and string-to-numeric coercions).
To create a variant that contains an array, you must first assign an array to the variant, calling this function using vtArray will not allocate the array.
The following example shows how to change a variant from vtR8 to string and than how to empty it:
vr=1.1e-1 ! var type is vtR8
VarChangeType(vr, vtBstr) ! vr is "0.11" var type vtBStr
VarChangeType(vr, vtEmpty) ! empty the variant
The following example shows how to change a variant from vtBStr to variant type of DLong/DDWord:
vrBStr="0x123456789ABCDEF0" ! var type is vtBStr
iSCode=VarChangeType(vr, vtI8, vrBStr) ! vtI8 - DLong
if iSCode
print "*** FAILED *** : iSCode = "; UCase(Str(iSCode,16))
else
print "vr = "; vr ! it prints "vr = 1311768467463790320"
endif
vrBStr="18446744073709551615" ! 2**64 - 1
iSCode=VarChangeType(vr, vtUI8, vrBStr) ! vtUI8 - DDWord
print "vr = "; vr ! vr = 18446744073709551615