Option Strict On 不允许后期绑定 system.array
我有以下代码,它返回 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
Function 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 根据查询返回整数或字符串。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以执行
myarray.GetValue(0)
而不是myArray(0)
。即使使用 Option Strict On,这也将起作用。You can do
myarray.GetValue(0)
instead ofmyArray(0)
. This will work even with Option Strict On.