rex*_*rex 1 vba function return-type
刚刚意识到我不知道答案,也没有关于SO的问题,所以在这里:
Function当没有指定VBA时,VBA中的例程的默认返回类型是什么?
根据文档,默认返回类型是a Variant,
除了以下情况:
DefInt I
' Now Itest will be Integer by default
Function Itest
End Function
Sub Test
Debug.Print TypeName(Itest) 'will print "Integer", remove the 1st line and you will get "Empty"
End Sub
Run Code Online (Sandbox Code Playgroud)
这是正确的,默认情况下DefInt I,所有以名称开头的名称I都是Integer.
你也可以使用DefBool,DefByte,DefCur, DefDate,DefDbl,DefInt,DefLng,DefLngLng,DefLngPtr,DefObj,DefSng,DefStr,DefVar
你甚至可以声明范围:
DefBool A-C
某些带有特殊后缀的名称也会表现不同:
Function a$()
End Function
Function b!()
End Function
Function c#()
End Function
Function d@()
End Function
Function e%()
End Function
Function f&()
End Function
Sub test()
Debug.Print "a$ : " & TypeName(a$) ' String
Debug.Print "b! : " & TypeName(b!) ' Single
Debug.Print "c# : " & TypeName(c#) ' Double
Debug.Print "d@ : " & TypeName(d@) ' Currency
Debug.Print "e% : " & TypeName(e%) ' Integer
Debug.Print "f& : " & TypeName(f&) ' Long
End Sub
Run Code Online (Sandbox Code Playgroud)
对于LongLong也有^,但仅适用于64位实现
| 归档时间: |
|
| 查看次数: |
931 次 |
| 最近记录: |