-1

I have the following function to parse command line arguments in 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 "-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

At runtime, it stops at line "Set GetProcessParams = result" in Case "-new" with message "Compile error: Object required"

What's wrong?

braX
  • 11,506
  • 5
  • 20
  • 33
Oscar
  • 13,594
  • 8
  • 47
  • 75

1 Answers1

1

The Set statement is only for assigning object references. Your result variable is an array of Variants, and arrays aren't object references in VB. If you want to copy an array into your own variable, you only need a regular assignment, without the Set keyword.