?
Solved

Put IE Windows into Object Array

Posted on 2005-03-04
6
Medium Priority
?
165 Views
Last Modified: 2010-05-02
Quick question:

I am using the following method to open an IE window:

ShellExecute(Me.hwnd, "open", "explorer.exe", url2, "", sStartup)

I have an loop that opens x number of these windows, and I want them put into an array. So I can access them like ie(0), ie(5) or whatever. How do I do this?

Secondly, how would I count the number of entries in an array like that?

Thanks a bunch.
0
Comment
Question by:Jimmy_A
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 14

Expert Comment

by:aelatik
ID: 13457253
Its an easy one, hope you understand the code :

Dim IE(5) As Object


Private Sub Command1_Click()
    Dim I As Long
    For I = LBound(IE) To UBound(IE)
        IE(I).quit
    Next I
End Sub

Private Sub Form_Load()
    Dim I As Long
    For I = LBound(IE) To UBound(IE)
        Set IE(I) = CreateObject("internetexplorer.application")
        IE(I).navigate "http://www.google.com"
        IE(I).Visible = True
    Next I
End Sub
0
 

Author Comment

by:Jimmy_A
ID: 13463350
Hi,

Thanks, that looks like what I want except for two things:

1)
I want to use that method to open the IE windows: ShellExecute(Me.hwnd, "open", "explorer.exe", url2, "", sStartup). This is so they have fresh sessions and such.

2)
I want the number of IE objects to be settable. The variable windows is the number of IE objects the user wants. However Dim IE(windows) As Object doesn't seem to work.

Thanks a lot :)
0
 

Author Comment

by:Jimmy_A
ID: 13464901
Hi,

Ignore the first question - I figured out how to fix that. I just need to know the answer to this:

I want the number of IE objects to be settable. The variable "windows" is the number of IE objects the user wants. However Dim IE(windows) As Object doesn't seem to work.

Thankies.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Accepted Solution

by:
aelatik earned 400 total points
ID: 13464954
You can't dim an array with a variable cause it needs a constant a value ! But there is a workaround, use :

Dim WINDOWS as long
       WINDOWS = 5
REDIM IE(WINDOWS) as object
0
 
LVL 32

Assisted Solution

by:Erick37
Erick37 earned 400 total points
ID: 13582746
Here is a quick example of how to add ie objects to a dynamic array.

Add a reference to "Microsoft Internet Controls"

Option Explicit

Private ie() As InternetExplorer
Private ndx As Long

Private Sub Command1_Click()
'
' Creates new ie objects and adds to the array
'
    'add another element to the array
    ReDim Preserve ie(ndx)
   
    'create a new ie
    Set ie(ndx) = New InternetExplorer
   
    ie(ndx).Visible = True
    ie(ndx).Navigate2 "about:blank"
   
    'calculate the next index for the array
    ndx = ndx + 1

End Sub


Private Sub Command2_Click()
'
' Loops the array and closes the ie objects
'
    Dim i As Long
   
    On Error Resume Next
    For i = LBound(ie) To UBound(ie)
        Debug.Print ie(i).LocationURL
        ie(i).Quit
        Set ie(i) = Nothing
    Next
   
    'reset the array
    Erase ie
   
End Sub
0
 
LVL 32

Expert Comment

by:Erick37
ID: 13582802
Basically the same idea using a collection instead:

Option Explicit

Private colIE As New Collection

Private Sub Command1_Click()
'
' Creates new ie objects and adds to the collection
'
    Dim ie As InternetExplorer
    Static i As Long
   
    'create a new ie
    Set ie = New InternetExplorer
   
    'add to the collection
    colIE.Add ie, CStr(i)
   
    ie.Visible = True
    ie.Navigate2 "about:blank"
   
    'increment the key value
    i = i + 1
   
End Sub


Private Sub Command2_Click()
'
' Loops the collection and closes the ie objects
'
    Dim ie As InternetExplorer
    Dim i As Long
   
    On Error Resume Next
    'loop the collection and quit
    For Each ie In colIE
        Debug.Print ie.LocationURL
        ie.Quit
        Set ie = Nothing
    Next
   
    'reset the collection
    For i = 1 To colIE.Count
        Debug.Print "Removing " & colIE.Item(i)
        colIE.Remove i
    Next
   
   
End Sub
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month10 days, 8 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question