kylefoley76
Well-known Member
- Joined
- Mar 1, 2010
- Messages
- 1,553
I have two loops each containing the same members. During the course of the loop, the size of the array gets increased. However, only the inner loop is being increased. The outer loop also increases but VBA still exits the loop before the upper bound is being reached. Here is a scheme of what is happening.
For i = 1 to ubound(tsent)
For j = 1 to ubound(tsent)
if a then
c = UBound(tsent) + 1 ReDim Preserve tsent(c)
tsent(c) = new_atomic
end if
next j
next i
Excel will eventually loop up to j = 12, but it won't loop pass i = 5 which is size of the array at the beginning. I tried creating two different arrays but that didn't help matters much. Here are some excerpts from the code, the irrelevant parts deleted:
For i = 1 to ubound(tsent)
For j = 1 to ubound(tsent)
if a then
c = UBound(tsent) + 1 ReDim Preserve tsent(c)
tsent(c) = new_atomic
end if
next j
next i
Excel will eventually loop up to j = 12, but it won't loop pass i = 5 which is size of the array at the beginning. I tried creating two different arrays but that didn't help matters much. Here are some excerpts from the code, the irrelevant parts deleted:
Code:
For t = 1 To UBound(sent)
temp_str = sent(t)
temp_relat = find_relat(temp_str)
relat = temp_relat(1)
obj = temp_relat(2)
subj = temp_relat(3)
positive = temp_relat(42)
transitive = temp_relat(6)
If transitive And positive = False Then
w = w + 1
ReDim Preserve tsent(w)
ReDim Preserve trsent(w)
tsent(w) = temp_str
trsent(w) = temp_str
End If
Next
For i = 1 To UBound(trsent)
temp_str = trsent(i)
temp_relat = find_relat(temp_str)
relat = temp_relat(1)
obj = temp_relat(2)
subj = temp_relat(3)
positive = temp_relat(42)
transitive = temp_relat(6)
prop_variable = temp_relat(45)
For j = 1 To UBound(tsent) Step 1
temp_str2 = tsent(j)
temp_relat2 = find_relat(temp_str2)
relat2 = temp_relat2(1)
obj2 = temp_relat2(2)
subj2 = temp_relat2(3)
positive2 = temp_relat2(42)
If relat = relat2 And obj = subj2 Then
If Not IsInArray(new_atomic, tsent) Then
c = UBound(tsent) + 1
ReDim Preserve tsent(c)
ReDim Preserve trsent(c)
tsent(c) = new_atomic
trsent(c) = new_atomic
[deleted code]
End If
End If
Next j
Next i
Next