&引用;“所需对象”;在VB6中赋值函数结果
我有以下函数来解析vb6中的命令行参数&引用;“所需对象”;在VB6中赋值函数结果,vb6,Vb6,我有以下函数来解析vb6中的命令行参数 Private Function GetProcessParams() As Variant Dim i As Integer Dim result() As Variant Select Case Command Case "-all" Set GetProcessParams = allProcess.Items Exit Function Case
Private Function GetProcessParams() As Variant
Dim i As Integer
Dim result() As Variant
Select Case Command
Case "-all"
Set GetProcessParams = allProcess.Items
Exit Function
Case "-new"
For i = 0 To allProcess.Count
Dim tmp As TableInfo
Set tmp = allProcess(i)
If tmp.isNew Then
ReDim result(i + 1)
Set result(i) = tmp
End If
Next i
Set GetProcessParams = result
Exit Function
Case Else
Dim subset() As String
subset = Split(Command, ",")
ReDim result(UBound(subset))
Dim val As String
For i = 0 To UBound(subset)
If IsNumeric(subset(i)) Then
Set result(i) = allProcess(CInt(subset(i)))
End If
Next i
Set GetProcessParams = result
Exit Function
End Select
End Function
在运行时,它在Case“-new”中的“Set GetProcessParams=result”行停止,并显示消息“Compile error:Object required”
怎么了?仅用于指定对象引用。您的
结果
变量是一个变量数组,数组在VB中不是对象引用。如果要将数组复制到自己的变量中,而不使用Set
关键字。请尝试删除Set
.allProcess.items(i)可能?如果从未满足tmp.isNew条件,并且从未在编译时或运行时重新删除空数组,会发生什么情况?