VarGetType
返回变量的内部表示类型.
VarGetType ( expression )
参数
返回值
返回表示表达式类型的字符串.
备注
详细说明参考 语言参考-数据类型.
当尝试转换浮点数或者字符串时, IsInt() 可能返回一个不同的结果, 例如调用 VarGetType 和值 2.0, 将返回"双精度型" 但 IsInt() 将为相同的值返回 1.
函数示例
#include <MsgBoxConstants.au3>
Local $aArray[2] = [1, "Example"]
Local $mMap[]
Local $dBinary = Binary("0x00204060")
Local $bBoolean = False
Local $pPtr = Ptr(-1)
Local $hWnd = WinGetHandle(AutoItWinGetTitle())
Local $iInt = 1
Local $fFloat = 2.0
Local $oObject = ObjCreate("Scripting.Dictionary")
Local $sString = "Some text"
Local $tStruct = DllStructCreate("wchar[256]")
Local $vKeyword = Default
Local $fuFunc = ConsoleWrite
Local $fuUserFunc = Test
MsgBox($MB_SYSTEMMODAL, "", _
"Variable Types" & @CRLF & @CRLF & _
"$aArray : " & @TAB & @TAB & VarGetType($aArray) & " variable type." & @CRLF & _
"$mMap : " & @TAB & @TAB & VarGetType($mMap) & " variable type." & @CRLF & _
"$dBinary : " & @TAB & @TAB & VarGetType($dBinary) & " variable type." & @CRLF & _
"$bBoolean : " & @TAB & VarGetType($bBoolean) & " variable type." & @CRLF & _
"$pPtr : " & @TAB & @TAB & VarGetType($pPtr) & " variable type." & @CRLF & _
"$hWnd : " & @TAB & @TAB & VarGetType($hWnd) & " variable type." & @CRLF & _
"$iInt : " & @TAB & @TAB & VarGetType($iInt) & " variable type." & @CRLF & _
"$fFloat : " & @TAB & @TAB & VarGetType($fFloat) & " variable type." & @CRLF & _
"$oObject : " & @TAB & VarGetType($oObject) & " variable type." & @CRLF & _
"$sString : " & @TAB & @TAB & VarGetType($sString) & " variable type." & @CRLF & _
"$tStruct : " & @TAB & @TAB & VarGetType($tStruct) & " variable type." & @CRLF & _
"$vKeyword : " & @TAB & VarGetType($vKeyword) & " variable type." & @CRLF & _
"MsgBox : " & @TAB & @TAB & VarGetType(MsgBox) & " variable type." & @CRLF & _
"$fuFunc : " & @TAB & @TAB & VarGetType($fuFunc) & " variable type." & @CRLF & _
"Func 'Test' : " & @TAB & VarGetType(Test) & " variable type." & @CRLF & _
"$fuUserFunc : " & @TAB & VarGetType($fuUserFunc) & " variable type.")
Func Test()
EndFunc ;==>Test
----------------------------------------
该函数可以通过命令 exect 调用
参见:
IsInt, IsFloat, IsString, IsBinary, IsArray
exect=$var_i=10||$var_i=String($var_i)||_ViewValues(VarGetType(Eval('var_i'))) ;; 将变量$var_i转换为字符串类型的示例
exect=$var_x=StringSplit('1|2|3|4','|',2)||_ViewValues(VarGetType(Eval('var_x')),'Тип~~данных~~переменной~~$var_x') ;; 数据类型定义
exect=$var_x=12345||_ViewValues(VarGetType(Eval('var_x')),'Тип~~данных~~переменной~~$var_x') ;; 数据类型定义
exect=$var_x=12345.001||_ViewValues(VarGetType(Eval('var_x')),'Тип~~данных~~переменной~~$var_x') ;; 数据类型定义
exect=$var_x='Hello!'||_ViewValues(VarGetType(Eval('var_x')),'Тип~~данных~~переменной~~$var_x') ;;数据类型定义
© Аверин Андрей для Total Commander Image Averin-And@yandex.ru
|