我有以下代码来获取分配给Array“UIDList()”的值。但是出于什么原因它只能获得最后一个值。你能否纠正可能出错的地方?
Dim strTest As String
Dim strarray() As String
Dim UIDList() As String
Dim intCount As Integer
Dim TotUID As Integer
Set oFS = oFSO.OpenTextFile("C:\Pro\test.txt")
txtpro = oFS.ReadAll
strTest = txtpro
strarray = Split(strTest, "=")
For intCount = LBound(strarray()) To UBound(strarray())
If InStr(strarray(intCount), "NAME") Then
UIDList() = Split(strarray(intCount), "NAME")
End If
Next
For TotUID = LBound(UIDList()) To UBound(UIDList())
Debug.Print UIDList(TotUID)
Next
答案 0 :(得分:0)
嵌套不当:
改为:
For intCount = LBound(strarray()) To UBound(strarray())
'Erase the array
Erase UIDList
If InStr(strarray(intCount), "NAME") Then
UIDList() = Split(strarray(intCount), "NAME")
End If
'/ Check if UIDList() has any elements
If Not (Not UIDList()) Then
For TotUID = LBound(UIDList()) To UBound(UIDList())
Debug.Print UIDList(TotUID)
Next
End If
Next