• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 167
  • Last Modified:

Put IE Windows into Object Array

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
Jimmy_A
Asked:
Jimmy_A
  • 2
  • 2
  • 2
2 Solutions
 
aelatikCommented:
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
 
Jimmy_AAuthor Commented:
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
 
Jimmy_AAuthor Commented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
aelatikCommented:
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
 
Erick37Commented:
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
 
Erick37Commented:
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

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now