arrays - VBA 代码:具有最小功能代码的值错误(数组输入/输出)
问题描述
我仍然是 VBA 编码的新手,并且有一些基本代码来测试功能性然后对其进行扩展。
某个代码块似乎完全破坏了功能(当我注释该块时,代码工作得很好),尽管在注释/未注释的代码块中没有什么“发生”。
Function Linearize(Old As Variant) As Variant
' Dim R As Integer
' Dim C As Integer
' Dim L As Integer
'
' R = UBound(Old, 1)
' C = UBound(Old, 2)
' L = R * C
Dim NewA As Variant
NewA = Old.Value2
Linearize = NewA
End Function
当我取消注释代码块时,出现 VALUE 错误...“公式中使用的值的数据类型错误。”
我只是没有看到 WTF 可能出错了?非常感谢您的帮助...非常感谢!
解决方案
通过删除错误调用来解决问题的一种简单方法:
Function linearize(old As Variant) As Variant
Dim R
Dim C
Dim L As Integer
R = UBound(old, 1)
C = UBound(old, 2)
L = R * C
Debug.Print L
End Function
在另一个子中,您可以调用该函数
Sub test2()
Dim myarray(1 To 10, 50 To 100)
linearize (myarray)
End Sub
推荐阅读
- javascript - 在 BlueprintJs DateInput 上添加“small”属性或 .bp3-small
- javascript - 更改用于在 React 中显示的集合
- swift - 无法使用“(Int,Int)”类型的参数列表调用“swapAt”
- algorithm - 构造 k 边连通子图
- ios - 如何在 Swift 中将计算的闭包属性转换为闭包?
- javascript - FlaskForm + Javascript
- java - 如果凭据不正确,如何将用户重定向到另一个 JSP 页面
- clojure - take-while 和 java-time/iterate 创建奇怪的结果
- java - 不调用join后的Spring Statemachine内部转换动作
- c - 为什么这个函数总是返回 0