473,657 Members | 2,474 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

For Each - Doesn't loop all IE objects

Ok here's the deal, the for each statment using VB 6 doesn't loop all
the objects. I would like it to close all the IE browsers that are
open, but it doesn't work. And now I'm concerned that its doing this
elsewhere in my code too, and the RETRY trick isn't an option.
Starting with say 16 open IE windows, this doesn't work, it exits the
for next while still having several IE windows open.
>>>> Dim SWs As New SHDocVw.ShellWi ndows
Dim IE As SHDocVw.WebBrow ser

For Each IE In SWs
IE.Quit
Next

Set SWs = Nothing
Set IE = Nothing
<<<<<<

However as a work around for this case this does work.
>

Dim SWs As New SHDocVw.ShellWi ndows
Dim IE As SHDocVw.WebBrow ser

RETRY:
For Each IE In SWs
IE.Quit
Next
If SWs.Count <> 0 Then GoTo RETRY

Set SWs = Nothing
Set IE = Nothing
<<<<<<

But as you can see this isn't usable in many cases when you need to
cycle all the objects.

Is this a bug that has a fix or am I just asking for too much?

(Please pardon the multi-post, the previous was in the wrong topic)
Nov 20 '05 #1
4 4141
Did you know that this is a VBNet newsgroups,

There are a lot of newsgroups about VB classic.

Microsoft.publi c.vb* (there are a bunch)

I hope you find your answer quick.

Cor
Nov 20 '05 #2
Out for blood 74,
In addition to Cor's comments that this is a VB6 newsgroup.
Is this a bug that has a fix or am I just asking for too much? Its rarely a good idea to modify a collection while in a For Each. I would
expect IE.Quit implicitly removes an item from the collection, hence you are
modifing it.

Its not that you are asking too much as you don't realize what is happening
to your collection... In VB.NET a number of collections actually throw an
exception (raise an error) when you attempt to do what you are doing.
For Each IE In SWs
IE.Quit
Next
I strongly suspect you are closing every other window. As the first time
through the loop IE.Quit will close the first window, causing the 2nd window
to become the first one. Then the loop will close the new 2nd window
(formally the 3rd), causing the 4th window to become the 2nd one. Then the
loop will close the 3rd window, formally the 5th, and so on...

When I need to "close" all the items in a collection I normally use a while
loop.

Something like:

While SWs.Count > 0
SWs(0).Quite
End While

There are variations of this loop that uses a For loop with a descending
index (close the last one, then the next to last one, then the 3rd to
last...) using a descending loop is good as you are not shifting elements
one position at a time as the while does.

Hope this helps
Jay
<ou***********@ hotmail.com> wrote in message
news:58******** *************** ***@posting.goo gle.com... Ok here's the deal, the for each statment using VB 6 doesn't loop all
the objects. I would like it to close all the IE browsers that are
open, but it doesn't work. And now I'm concerned that its doing this
elsewhere in my code too, and the RETRY trick isn't an option.
Starting with say 16 open IE windows, this doesn't work, it exits the
for next while still having several IE windows open.
>>>>> Dim SWs As New SHDocVw.ShellWi ndows
Dim IE As SHDocVw.WebBrow ser

For Each IE In SWs
IE.Quit
Next

Set SWs = Nothing
Set IE = Nothing
<<<<<<

However as a work around for this case this does work.
>>>

Dim SWs As New SHDocVw.ShellWi ndows
Dim IE As SHDocVw.WebBrow ser

RETRY:
For Each IE In SWs
IE.Quit
Next
If SWs.Count <> 0 Then GoTo RETRY

Set SWs = Nothing
Set IE = Nothing
<<<<<<

But as you can see this isn't usable in many cases when you need to
cycle all the objects.

Is this a bug that has a fix or am I just asking for too much?

(Please pardon the multi-post, the previous was in the wrong topic)

Nov 20 '05 #3
Jay,

Please do not disrupt the Garden

:-)

Cor
Nov 20 '05 #4
Doh!
In addition to Cor's comments that this is a VB6 newsgroup.
That should be this is not a VB6 newsgroup, this is a VB.NET newsgroup.

Jay

"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. .. Out for blood 74,
In addition to Cor's comments that this is a VB6 newsgroup.
Is this a bug that has a fix or am I just asking for too much? Its rarely a good idea to modify a collection while in a For Each. I would
expect IE.Quit implicitly removes an item from the collection, hence you

are modifing it.

Its not that you are asking too much as you don't realize what is happening to your collection... In VB.NET a number of collections actually throw an
exception (raise an error) when you attempt to do what you are doing.
For Each IE In SWs
IE.Quit
Next
I strongly suspect you are closing every other window. As the first time
through the loop IE.Quit will close the first window, causing the 2nd

window to become the first one. Then the loop will close the new 2nd window
(formally the 3rd), causing the 4th window to become the 2nd one. Then the
loop will close the 3rd window, formally the 5th, and so on...

When I need to "close" all the items in a collection I normally use a while loop.

Something like:

While SWs.Count > 0
SWs(0).Quite
End While

There are variations of this loop that uses a For loop with a descending
index (close the last one, then the next to last one, then the 3rd to
last...) using a descending loop is good as you are not shifting elements
one position at a time as the while does.

Hope this helps
Jay
<ou***********@ hotmail.com> wrote in message
news:58******** *************** ***@posting.goo gle.com...
Ok here's the deal, the for each statment using VB 6 doesn't loop all
the objects. I would like it to close all the IE browsers that are
open, but it doesn't work. And now I'm concerned that its doing this
elsewhere in my code too, and the RETRY trick isn't an option.
Starting with say 16 open IE windows, this doesn't work, it exits the
for next while still having several IE windows open.
>>>>>>>

Dim SWs As New SHDocVw.ShellWi ndows
Dim IE As SHDocVw.WebBrow ser

For Each IE In SWs
IE.Quit
Next

Set SWs = Nothing
Set IE = Nothing
<<<<<<

However as a work around for this case this does work.
>>>>>>>

Dim SWs As New SHDocVw.ShellWi ndows
Dim IE As SHDocVw.WebBrow ser

RETRY:
For Each IE In SWs
IE.Quit
Next
If SWs.Count <> 0 Then GoTo RETRY

Set SWs = Nothing
Set IE = Nothing
<<<<<<

But as you can see this isn't usable in many cases when you need to
cycle all the objects.

Is this a bug that has a fix or am I just asking for too much?

(Please pardon the multi-post, the previous was in the wrong topic)


Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2582
by: Peter Abel | last post by:
I have an application, which is an instance of a class with a deeply nested object hierarchy. Among others one method will be executed as a thread, which can be stopped. Everything works fine except that when deleting the main instance - after the thread has been stopped - the __del__ method will not be carried out. Tough a simple example works as expected: >>> class A: .... def __init__(self):
0
2551
by: Kingdom | last post by:
I Need some serious help here. strugling novis with ASP and javascript any help would be greatly appreciated The script below does exactly what I want it to do for each product on the two passes it makes however I would like the entire script to loop 34 times and on each of those 30 loops also write the product and the price (only) onto the page building a compleate list of all the products selected over the 34 loops ending with a total...
11
3512
by: Laphan | last post by:
Hi All I'm using .getRows() with a local var array instead of doing a recursive loop so that I'm being a good ASP newvbie and closing my object i/o's (the recordset in this case) as quick as possible. My problem is that I can't seem to use this to complete good effect because the IsArray statement doesn't seem to work with a local var array that has or has not been populated with the .getRows() property.
3
3050
by: pertheli | last post by:
Hello, I have a large array of pointer to some object. I have to run test such that every possible pair in the array is tested. eg. if A,B,C,D are items of the array, possible pairs are AB, AC, AD, BC and CD. I'm using two nested for loop as below, but it is running very slow whenever I access any data in the second loop.
32
6506
by: Joe Rattz | last post by:
Hmmm, I wrote the following code. I want an array of bools and I want to intialize them to false. bool bits = new bool; foreach(bool bit in bits) { bit = false; } The compiler complains on the "bit = false;" stating that bit is read-only.
36
2092
by: Cap'n Ahab | last post by:
I have used VB3 - VB6, so learning all this OO stuff is reasonably new to me (although I looked at Java a few years ago). Anyway, I thought I would write a small class to begin with, with a property and 2 methods, along with a constructor (where you use New(), I think, yes?). So, I decided to create a class that represents a die, which can be rolled - using a Roll() method - and which has a property to find out the value on the face of...
5
1541
by: fireball | last post by:
please help newbie I need to create a lot of objects the same type (let's say: schemas) I wish to use paramerized block in loop to do so. - how to put names of my objects to such control-flow? belss you for help
10
8147
by: Hendri Adriaens | last post by:
Hi, I'm trying to automate the creation of an excel file via COM. I copied my code below. I read many articles about how to release the COM objects that I create. The code below runs just fine and excel is closed. But there are some commented lines: //xlSeries.XValues = xlWs.get_Range("B2", "B4"); // makes com objects, but which...
10
2935
by: fig000 | last post by:
HI, I'm new to generics. I've written a simple class to which I'm passing a generic list. I'm able to pass the list and even pass the type of the list so I can use it to traverse it. It's a generic list of business objects. I'm able to see that the type is the correct one in the debugger. However when I try to traverse the list using the type I can't compile. The same type variable I've verified as being passed
0
8413
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8842
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8617
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7352
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6176
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2742
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1733
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.