vba 如何在VBA中找到返回类型

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10481867/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 16:03:34  来源:igfitidea点击:

How to find the return type in VBA

vbams-accessaccess-vba

提问by Mahyar

I have a MS Access application and have problem to find a return type of function. Is there a way to find return type of object? I have type mismatch error.

我有一个 MS Access 应用程序,但在查找函数的返回类型时遇到问题。有没有办法找到对象的返回类型?我有类型不匹配错误。

回答by HansUp

If it is a built-in function, look at the Access help topic.

如果是内置函数,请查看 Access 帮助主题。

If it is a user-defined function, examine its definition.

如果它是用户定义的函数,请检查其定义。

If you can do neither, use the TypeName()function to tell you the data type returned by YourFunction().

如果两者都做不到,请使用该TypeName()函数告诉您返回的数据类型YourFunction()

Debug.Print TypeName(YourFunction())

If YourFunction()returns a variant, TypeName()will tell you the variant subtype.

如果YourFunction()返回一个变体,TypeName()会告诉你变体subtype

Heinzi suggested VarType()instead of TypeName(). I habitually reach for TypeName()first simply because it's quicker for me, and I'm seldom concerned with its limitations. However I agree with Heinzi; VarType()is better.

Heinzi 建议VarType()代替TypeName(). 我习惯性地使用TypeName()first 只是因为它对我来说更快,而且我很少关心它的局限性。不过我同意 Heinzi 的观点。VarType()更好。

JP. offered two other useful suggestions. First, you can create a simple procedure which declares a Variantvariable and assign your function's return value to the variable. Then add a temporary break point (with F9) on the first Debug.Printline, run the procedure, use F8to move through it line by line, and monitor the variable's value in the Locals Window. (Open that window from the VB editor's main menu. View -> Locals Window)

J.P。提供了另外两个有用的建议。首先,您可以创建一个简单的过程,它声明一个Variant变量并将函数的返回值分配给该变量。然后F9在第一Debug.Print行添加一个临时断点(用),运行该过程,使用F8逐行移动,并在局部窗口中监视变量的值。(从 VB 编辑器的主菜单打开该窗口。查看 -> 本地窗口)

Public Sub examine_YourFunction()
    Dim varFoo As Variant
    Debug.Print "start"
    varFoo = YourFunction()
    Debug.Print varFoo
End Sub

And second, for built-in functions that have a return type, you can take advantage of Intellisense to see the return type as you are typing the function name and/or the parameters.

其次,对于具有返回类型的内置函数,您可以在键入函数名称和/或参数时利用 Intellisense 查看返回类型。