【问题标题】:Option Strict On disallows late binding with system.arrayOption Strict On 不允许后期绑定 system.array
【发布时间】:2011-07-19 14:58:29
【问题描述】:

我有以下代码返回 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

"myarray(tel)" 当我打开选项显式时给出“Option Strict On 不允许后期绑定”问题。 我该如何解决这个问题,wmi 根据查询返回整数或字符串。

【问题讨论】:

  • 哪一行代码抛出了后期绑定的错误?您是否可以突出显示该行或重复该行?您可能还希望重新阅读您的问题,很难准确说出您在问什么。

标签: vb.net option-explicit


【解决方案1】:

您可以使用myarray.GetValue(0) 代替myArray(0)。即使 Option Strict On 也可以使用。

【讨论】:

    猜你喜欢
    • 2012-09-04
    • 2015-10-26
    • 1970-01-01
    • 2019-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多