出现类型不匹配!! 求高手指教!!
代码如下:
Private Sub test_Click()
Dim a(3) As Long
Dim s As Long
a(0) = 3
a(1) = 4
a(2) = 5
s = triarea(a()) ‘ 此处总是提示 类型不匹配 换成a(0)就变成下标越界了
Print s
End Sub
Public Function triarea(ParamArray vv())
' var input 1 out
Dim u As Long, i As Long
' ' ' ' ' Uncomment line below to use this function from a Microsoft Excel spreadsheet
' IsXL = True
u = UBound(vv)
If u = 0 And VarType(vv(0)) = vbVariant + vbArray Then
v = vv(0)
u = UBound(v)
Else
v = vv
End If
Dim prhs_mat(0 To 63)
Dim prhs(0 To 63) As Long
For i = 0 To u
prhs_mat(i) = ToMatrix(v(i))
prhs(i) = prhs_mat(i).Handle
Next
Dim plhs(1 To 1) As Long
Dim e As Long, emsg As String * 1024
e = triarea_v(emsg, 1, plhs(1), u + 1, prhs(0))
Set triarea = New Matrix
triarea.Handle = plhs(1)
If IsXL Then
triarea = triarea.Simple
Else
End If
If e > 0 Then
emsg = Left$(emsg, e)
Err.Raise 999, , emsg
End If
End Function
本意是想调用函数的 可就是不对劲
本人初学 很多问题不懂向各位求救了!!
[解决办法]
阿勇 Function triarea(ParamArray vv())我也觉得有疑惑,不过试了后是可以的,在过程中可用call,也可以声明一个变体形变量调用,其应该同等于Function triarea(ParamArray vv()) as variant 吧?
说实话以前不了解ParamArray,现在试了一下,传递的参数可以不确定类型和个数,感觉有很方便的地方:
Function test(ParamArray vv())
Dim v
Dim i
Dim s, n
For Each v In vv
If IsArray(v) Then
If IsNumeric(v(0)) Then
For i = 0 To UBound(v)
n = n + CInt(v(i))
Next
s = CStr(n)
Else
For i = 0 To UBound(v)
s = s & CStr(v(i))
Next
End If
ElseIf IsObject(v) Then
s = v.Name
Else
s = CStr(v)
End If
Print s
s = vbNullString
Next
End Function
Private Sub Command1_Click()
Dim a As Variant
Dim b(2) As Long
Dim s As String
Dim c As CommandButton
Set c = Command1
Dim v As Variant
a = Array( "a ", 1, "B ")
b(0) = 1
b(1) = 2
b(2) = 3
s = "test "
v = test(a, b, s, c)
End Sub