vba - 在 MS ACCES / VBA 中将参数传递给函数的方法
问题描述
我目前正在努力理解 MS Access VBA 中其他人的代码。
他定义了一个这样的函数
Function transferTable(tableType As String) As Boolean
当函数被调用时,它看起来像这样
transferTable = True
根据参数 tableType 有几个选择案例语句。例如
Select Case tableType
Case "rc": range = "A" & row & ":AD" & row
Case "66": range = "A" & row & ":M" & row
Case "25": range = "A" & row & ":L" & row
Case "67": range = "A" & row & ":L" & row
Case "77": range = "A" & row & ":L" & row
Case "47": range = "A" & row & ":L" & row
Case "c2": range = "A" & row & ":S" & row
End Select
我只是不明白我们在哪里将“值”传递给 tableType。我在 VBA 代码中找不到它,并且没有一个查询/表包含名为 tableType 的列。
有没有其他方法可以将参数传递给 MS Access VBA 中的函数?我仍然是编程的新手......
解决方案
transferTable = True
这不是函数的调用。这只能在函数内,在分配函数返回值的部分代码中。
这是一个简单的例子;这个函数接受一个Long
参数,True
如果参数大于0则返回,False
否则:
Public Function MyFunction(ByVal someParameter As Long) As Boolean
MyFunction = (someParameter > 0)
End Function
这是您在赋值运算符左侧看到函数名称的唯一地方。
在调用该函数的地方,代码可能如下所示:
MyFunction 42
或者像这样:
result = MyFunction(42)
或者像这样:
If MyFunction(42) Then
这就是将参数传递给任何Sub
或Function
过程的方式......没有其他方法。
考虑这个(众所周知的?)函数用法:
MsgBox "message"
和:
result = MsgBox("message", vbYesNo)
或者:
If MsgBox("message", vbYesNo) = vbYes Then
推荐阅读
- sql - 将表连接到自身以获取缺少日期的去年结果
- soap - 绕过 NetSuite SOAP 请求中的警告
- typescript - 什么是| Typescript 中使用的运算符?
- javascript - 如何使用 Angular 5 指令隐藏和显示表树行
- python - 从静态 xml 文件打印数据
- asp.net-mvc - Helper ShowTree 显示子项 2 次
- python - Keras 深度学习网络中的参数数量
- c - 块设备 - 在不使用探测功能的情况下获取结构设备
- akka - 名称无效的 Akka 演员选择
- wordpress - 使用 Axios 通过 slug 过滤时 WordPress REST API 不起作用