将数组中的项目与 VB6 中的变体中的项目进行比较
Compare items in an Array to items in a Variant in VB6
我在 VB6 中有一个包含数千个字符串的变体。
我也有定长数组
我需要比较每个的内容并将匹配的内容添加到列表中。
if array(i) = variant(1,i) then
'add to list
End if
我不知道如何正确地迭代两者以便进行比较,因为我用来迭代 Variant() 的方法在遍历每个项目后停止。所以它从不检查数组中是否有任何项目等于 i+1。
Private Sub dp_Click()
Dim fArray
fArray = Array("a", "b", "c")
LstAPens.ListItems.Clear
LstUPens.ListItems.Clear
For x = 0 To UBound(fArray)
Dim i As Long, m As Integer
'Do Until batcharray(0, i) = "End"
' tmpArray(i) = UCase(batcharray(1, i))
'Loop
Do Until batcharray(0, i) = "End"
If (InStr(1, UCase(batcharray(1, i)), UCase(fArray(x))) > 0) Then
LstAPens.ListItems.Add
With LstAPens.ListItems(m + 1)
.SubItems(1) = batcharray(1, i) 'Tagname
End With
m = m + 1
End If
i=i+1
Loop
Next x
End Sub
我尝试将 Variant 转换为数组,但没有成功。
唯一找到的项目是数组中的第一个,然后 Variant 在到达末尾时不再迭代。
如何遍历本例中名为 batchArray 的 Variant,并将其与数组的内容进行比较?
这确实不是 Variant
问题,只是 looping/control 变量问题。
即使您在主循环中有 DIM 语句,VB 也不会将其视为 "redeclaration" 并且 reset/reinitialize 它在 UNTIL 循环之前的值。结果,'i' 将增加到 1,然后在外循环的迭代之间保留其值,因此停留在 batchArray 中的单个值上并且迭代停止。
将声明移到循环外,在 UNTIL
循环之前将其重置为 0,看看是否能解决您的问题:
Dim i as Long
For x = 0 To UBound(fArray)
Dim m As Integer
i = 0
Do Until batcharray(0, i) = "End"
If (InStr(1, UCase(batcharray(1, i)), UCase(fArray(x))) > 0) Then
LstAPens.ListItems.Add
With LstAPens.ListItems(m + 1)
.SubItems(1) = batcharray(1, i) 'Tagname
End With
m = m + 1
End If
i=i+1
Loop
Next x
我在 VB6 中有一个包含数千个字符串的变体。
我也有定长数组
我需要比较每个的内容并将匹配的内容添加到列表中。
if array(i) = variant(1,i) then
'add to list
End if
我不知道如何正确地迭代两者以便进行比较,因为我用来迭代 Variant() 的方法在遍历每个项目后停止。所以它从不检查数组中是否有任何项目等于 i+1。
Private Sub dp_Click()
Dim fArray
fArray = Array("a", "b", "c")
LstAPens.ListItems.Clear
LstUPens.ListItems.Clear
For x = 0 To UBound(fArray)
Dim i As Long, m As Integer
'Do Until batcharray(0, i) = "End"
' tmpArray(i) = UCase(batcharray(1, i))
'Loop
Do Until batcharray(0, i) = "End"
If (InStr(1, UCase(batcharray(1, i)), UCase(fArray(x))) > 0) Then
LstAPens.ListItems.Add
With LstAPens.ListItems(m + 1)
.SubItems(1) = batcharray(1, i) 'Tagname
End With
m = m + 1
End If
i=i+1
Loop
Next x
End Sub
我尝试将 Variant 转换为数组,但没有成功。
唯一找到的项目是数组中的第一个,然后 Variant 在到达末尾时不再迭代。
如何遍历本例中名为 batchArray 的 Variant,并将其与数组的内容进行比较?
这确实不是 Variant
问题,只是 looping/control 变量问题。
即使您在主循环中有 DIM 语句,VB 也不会将其视为 "redeclaration" 并且 reset/reinitialize 它在 UNTIL 循环之前的值。结果,'i' 将增加到 1,然后在外循环的迭代之间保留其值,因此停留在 batchArray 中的单个值上并且迭代停止。
将声明移到循环外,在 UNTIL
循环之前将其重置为 0,看看是否能解决您的问题:
Dim i as Long
For x = 0 To UBound(fArray)
Dim m As Integer
i = 0
Do Until batcharray(0, i) = "End"
If (InStr(1, UCase(batcharray(1, i)), UCase(fArray(x))) > 0) Then
LstAPens.ListItems.Add
With LstAPens.ListItems(m + 1)
.SubItems(1) = batcharray(1, i) 'Tagname
End With
m = m + 1
End If
i=i+1
Loop
Next x