Option Strict On禁止使用后期绑定与system.array。

3
我有以下代码,它返回WMI信息(未知数组)。
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

ConvertArray函数将其转换为字符串值。

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

当我打开Option Explicit选项时,使用"myarray(tel)"会出现"Option Strict On disallows late binding"问题。该如何解决?WMI根据查询返回整数或字符串。


哪一行代码导致了关于后期绑定的错误?你能否突出显示该行或重复它?您可能还希望重新阅读您的问题,因为很难确切地知道您在问什么。 - keithwill
1个回答

7

您可以使用myarray.GetValue(0)代替myArray(0)。即使开启了Option Strict,这也可以正常工作。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接