Visual Basic/VB >> For each loop
by Rick Mogstad » Wed, 08 Oct 2003 00:39:19 GMT
What happens during a for each loop, if one of the members of the collection was present at the
beginning of the loop, but is missing by the end? For example, say you are looping through the
forms collection, and you close a form right after it gets into the for each loop for the first
time. Will it throw an error?
Visual Basic/VB >> For each loop
by Lofty » Wed, 08 Oct 2003 00:42:53 GMT
Yes, it will throw an error. I tried to use this to remove nodes from a
tree (For Each nodNode in tvTree.Nodes) and it did, indeed, throw an error.
:-(
--
Lofty
http://www.brainache.demon.co.uk
collection was present at the
are looping through the
each loop for the first
Visual Basic/VB >> For each loop
by Frampton Firesword » Wed, 08 Oct 2003 05:08:39 GMT
Try the following and see if you get any errors
Private Sub Form_Load()
Dim col1 As Collection
Set col1 = New Collection
Dim varnum
col1.Add 1, "one"
col1.Add 2, "two"
col1.Add 3, "three"
For Each varnum In col1
Debug.Print "Found item " & varnum
If varnum = 2 Then col1.Remove "three"
Next
End Sub
collection was present at the
are looping through the
each loop for the first
For each loop
by Frampton Firesword » Wed, 08 Oct 2003 05:09:16 GMT
The treeview it must use an array based system that doesn't reorder on
removal
error.
you
Similar Threads
1. For Next loop & looping early
2. Loop within (InStr) Loop problem - how do I re-read file in se
3. Time out for-each loop and While loop
Is there any way to set Max_Time for a for-each loop or for a while
loop, so that the loop terminates
after that time -limit and goes to the next thing in the loop that
means to the next Counter ....
Thanks in Advance.
Archan
4. Breaking a for loop and nested for loop????
5. Timed loop - loop for 10 seconds for objNet.MapNetworkDrive
I am attempting to shorten the default timeout period when mapping a network
drive via a logon script (useful when the server is down) from the default of
45-50 seconds to 10 seconds. Users with a dozen or more mappings affected
like this can end up waiting 10+ minutes for the logon script to complete.
Does anyone know a way to do this in VBScript? (NOTE: I don't want to go the
one size fits all setting a timeout on the whole script via Properties >
Script > Stop script after specified number of seconds.)
i.e.
Do (loop for up to the next 10 seconds while waiting for this operation to
complete)
objNet.MapNetworkDrive Drive_Letter,UNC_Path_to_Map
Loop
-Chris
6. Loop de Loop - Visual Basic/VB
7. Why Doesn't This Loop-within-a-Loop Work?
So what I'm trying to do is loop through all the frames in my
document, and see if they're on the same page as text with the style
"Heading 2". Here's the code:
Dim SrcRg As Range
Dim frm As frame
Set SrcRg = ActiveDocument.Range
For Each frm In ActiveDocument.Frames
With SrcRg.Find
.ClearFormatting
.Text = ""
.Format = True
.Style = ActiveDocument.Styles("Heading 2")
.Forward = True
.Wrap = wdFindStop
Do While .Execute
If SrcRg.Information(wdActiveEndAdjustedPageNumber) =
frm.Range.Information(wdActiveEndAdjustedPageNumber) Then
MsgBox SrcRg.Information(wdActiveEndAdjustedPageNumber)
Exit Do
End If
Loop
End With
Next
What I'd like this to do is loop through all the frames, and for each
one search through all the Heading 2's and, if it finds one on the
page that the frame is on, print out a message box accordingly. In
practice, it just prints out the first page that has a frame and a
Heading 2 on... and that's it.
Can anyone smart tell me what's going on here?
8. Loops within Loops. - MS Word&VBA