3

I have the following code which return wmi information (unknown array)

For Each objMgmt In oquery.Get()
  For Each theproperty In objMgmt.Properties
    If (TypeOf objMgmt(theproperty.Name) Is System.Array) Then
      myrow(theproperty.Name) = ConvertArray(CType(objMgmt(theproperty.Name), Array)).Trim
    end if                      
  next
next

Function ConvertArray converts this to a string value.

Function ConvertArray(ByVal myarray As System.Array) As String
    Dim tel As Integer
    Dim res As String = ""
    If myarray.Length = 0 Then
        Return ""
    End If
    If myarray.Length = 1 Then
        res = myarray(0).ToString
    Else
        For tel = 0 To myarray.Length - 1
            If TypeOf myarray(tel) Is UInt16 Then
                res = res + "[" + CType(myarray(tel), UInt16).ToString + "] , "
            Else
                res = res + CStr(myarray(tel)) + " , "
            End If
        Next
        res = Mid(res, 1, Len(res) - 2)
    End If
    Return res
End Function

"myarray(tel)" give "Option Strict On disallows late binding" problem when I turn option explicit on. How can I solve this, wmi returns integers or strings depending on the query.

WilfriedVS
  • 416
  • 1
  • 4
  • 13
  • Which line of code is throwing the error about late binding? Is it possible for you to highlight the line or repeat it? You may wish to reread your question as well, its kind of hard to tell exactly what you are asking. – keithwill Jul 19 '11 at 15:15

1 Answers1

7

You can do myarray.GetValue(0) instead of myArray(0). This will work even with Option Strict On.

Meta-Knight
  • 17,626
  • 1
  • 48
  • 58