我的想法是创建一个函数来传递像这样的双数组:
Function pass(a() As Double, b() as double) As Boolean
Dim i As Integer, j As Integer
ReDim a(0 To UBound(b, 1), 0 To UBound(b, 2))
For i = 0 To UBound(a, 1)
For j = 0 To UBound(a, 2)
a(i, j) = b(i, j)
Next
Next
End Function
使人可以使用:
pass(a,b)
然后是a = b。
a=b
不起作用..(天哪,我想念matlab ..)
好,回到问题所在:
这对于两个双精度数组很好用,但是如果我得到了一个变体,并且当我使用它时我可以得到一个变体,那么这是行不通的。那么是否存在将变量值传递给双精度数组的解决方案?数据的结构类似于double数组,但没有double()类型。
答案 0 :(得分:1)
为解决这个问题,我将删除参数的类型。
Sub test()
Dim VarArry(0 To 4, 0 To 4) As Variant
Dim DblArry(0 To 4, 0 To 4) As Double
Dim VarAssing() As Variant
Dim DblAssing() As Double
Dim c As Boolean
VarArry(0, 1) = 34
DblArry(0, 1) = 34
c = pass(VarAssing, VarArry)
Debug.Print (TypeName(VarAssing))
Debug.Print (VarAssing(0, 1))
c = pass(VarAssing, DblArry)
Debug.Print (TypeName(VarAssing))
Debug.Print (VarAssing(0, 1))
c = pass(DblAssing, VarArry)
Debug.Print (TypeName(DblAssing))
Debug.Print (VarAssing(0, 1))
c = pass(DblAssing, DblArry)
Debug.Print (TypeName(DblAssing))
Debug.Print (VarAssing(0, 1))
End Sub
Function pass(a, b) As Boolean
Dim i As Integer, j As Integer
ReDim a(0 To UBound(b, 1), 0 To UBound(b, 2))
For i = 0 To UBound(a, 1)
For j = 0 To UBound(a, 2)
a(i, j) = b(i, j)
Next
Next
End Function
输出如下
Variant()
34
Variant()
34
Double()
34
Double()
34