在VBA函数调用中,括号的使用规则是什么? [英] What are the rules governing usage of brackets in VBA function calls?

查看:187
本文介绍了在VBA函数调用中,括号的使用规则是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于在要传递给我定义的Sub的参数周围使用方括号引起的VBA(访问2003)中的编译器错误",我刚刚经历了30分钟的烦恼.

I've just had an irritating 30 minutes on a "compiler error" in VBA (Access 2003) caused by my use of brackets around the arguments I'm passing to a Sub I defined.

我一直在寻找关于什么时候需要/适当/不合适/禁止使用方括号的体面的文章/教程/说明,但是找不到任何明确的指南.

I've been searching to find a decent article/tutorial/instruction as to when brackets are necessary/appropriate/inappropriate/forbidden, but can't find any clear guidelines.

推荐答案

来自此处:

使用VBScript调用语句来调用子例程 当您希望调用子例程时,使用Call语句是可选的.与Sub一起使用时,Call语句的目的是允许您将参数列表括在括号中.但是,如果子例程未传递任何参数,则在使用Call语句调用Sub时,仍不应使用括号.

Using the VBScript Call Statement to Call a Subroutine The use of Call statement is optional when you wish to call a subroutine. The purpose of the Call statement when used with a Sub is to allow you to enclose the argument list in parentheses. However, if a subroutine does not pass any arguments, then you still should not use parentheses when calling a Sub using the Call statement.

Call MySubroutine

如果子例程具有参数,则在使用Call语句时必须使用括号.如果有多个参数,则必须用逗号分隔参数.

If a subroutine has arguments, you must use parentheses when using the Call statement. If there is more than one argument, you must separate the arguments with commas.

Call MySubroutine(intUsageFee, intTimeInHours, "DevGuru") 

调用函数 调用函数有两种可能的方法.您可以直接调用该函数(仅按名称),也可以使用VBScript Call语句来调用它.

Calling the Function There are two possible ways to call a function. You may either call the function directly, by name only, or you may call it by using the VBScript Call statement.

按名称调用函数 当直接通过名称调用函数且未分配返回值时,以下所有内容均为合法语法:

Calling a Function by Name When calling a function directly by name and when there is no assignment to a returned value, all of the following are legal syntax:

MyFunction
MyFunction()
MyFunction intUsageFee, intTimeInHours, "DevGuru"

如果要返回值,可以将函数分配给变量.请注意,如果有一个或多个参数,则必须使用括号.

If you want a returned value, you can assign the function to a variable. Note that if there is one or more arguments, you must use the parentheses.

returnval = MyFunction
returnval = MyFunction()
returnval = MyFunction(intUsageFee, intTimeInHours, "DevGuru") 

这篇关于在VBA函数调用中,括号的使用规则是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆