奇怪的 VBA 预期语句结束错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15395338/
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
Weird VBA Expected End of Statement Error
提问by user2004245
I started working on creating a custom function in Access 2010, using the VBA Editor, but I keep getting an Expected End of Statement Error.
我开始使用 VBA 编辑器在 Access 2010 中创建自定义函数,但我不断收到预期的语句结束错误。
Here's the code:
这是代码:
Public Function getPayTotal(ByVal StudentID As Long) As Long
Return StudentID
End Function
I have absolutely no idea why this isn't working. The debug keeps sending me back to the Return StudentID line. Am I over looking something incredibly simple?
我完全不知道为什么这不起作用。调试不断将我发送回返回学生 ID 行。我是不是在看一些非常简单的东西?
Thanks.
谢谢。
回答by Fionnuala
Not return:
不回:
Public Function getPayTotal(ByVal StudentID As Long) As Long
getPayTotal = StudentID
End Function
You can call the function like so:
您可以像这样调用函数:
Sub theFunction
getPayTotal 21
''Or
Call getPayTotal(21)
''Or
r = getPayTotal(21)
End Sub
In other words, be careful with the parentheses.
换句话说,要小心括号。