?
Solved

Multiple Download Inet1

Posted on 2003-03-20
8
Medium Priority
?
357 Views
Last Modified: 2010-05-18
I am trying to download a number of items simultaneously.

I have 2 Inet control on my form (Inet1(0) and Inet1(1)) and this is a subset of the code I am using:

dim item1 as string
dim item2 as string

Inet1(0).RequestTimeout = 10
Inet1(1).RequestTimeout = 10
DoEvents
item1 = myform.Inet1(0).OpenURL("http://www.google.com")
item2 = myform.Inet1(1).OpenURL("http://www.experts-exchange.com")

The problem is that it performs item1 before doing item2, how do I make the program do it simultaneously?
0
Comment
Question by:cMh
[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
  • 4
  • 3
8 Comments
 
LVL 2

Expert Comment

by:saurabhgupta
ID: 8175235
Hi cMh,
Use the Execute method method to make asynchronous call
Inet1.Execute URL, "GET"

Private Sub Inet1_StateChanged(ByVal State As Integer)
    Select Case State
    Case icResponseCompleted
    On Error Resume Next
    Dim tmpData As String
    tmpData = Inet1.GetChunk(1024, icString)
    While Len(tmpData) <> 0
        DoEvents
        HTML = HTML + tmpData
        tmpData = Inet1.GetChunk(1024, icString)
    Wend
    Me.Hide
    Case icError
    End Select
End Sub

Regards
Saurabh
0
 

Author Comment

by:cMh
ID: 8175307
Thanks for the quick reply...

What is the _StateChanged sub for?
0
 
LVL 2

Expert Comment

by:saurabhgupta
ID: 8175403
cMh,
> What is the _StateChanged sub for?
This event is fired in case of asynchronous calls to report the current state of the request.

Private Sub Inet1_StateChanged(ByVal State As Integer)
    Select Case State
    Case icResolvingHost
    Case icConnecting
    Case icConnected
    Case icRequestSent
    Case icReceivingResponse
    Case icDisconnecting

    Case icResponseCompleted
    On Error Resume Next
    Dim tmpData As String
   Dim MyData As String  
  tmpData = Inet1.GetChunk(1024, icString)
    While Len(tmpData) <> 0
        DoEvents
        MyData = MyData + tmpData
        tmpData = Inet1.GetChunk(1024, icString)
    Wend
 'process MyData

    Case icError
 'handle error
    End Select
End Sub


Regards
Saurabh
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:cMh
ID: 8176010
I haven't tested this yet but assuming it works, how do I make the program pause until all of the information from both Inet controls is collected?
0
 
LVL 2

Accepted Solution

by:
saurabhgupta earned 200 total points
ID: 8176688
Option Explicit

Private Type SECURITY_ATTRIBUTES
    nLength As Long
    lpSecurityDescriptor As Long
    bInheritHandle As Long
End Type

Private Const WAIT_FAILED = &HFFFFFFFF       'Our WaitForSingleObject failed to wait and returned -1
Private Const WAIT_OBJECT_0 = &H0&           'The waitable object got signaled '
Private Const WAIT_ABANDONED = &H80&         'We got out of the waitable object
Private Const WAIT_TIMEOUT = &H102&          'the interval we used, timed out.

'Message constants
Private Const QS_HOTKEY = &H80
Private Const QS_KEY = &H1
Private Const QS_MOUSEBUTTON = &H4
Private Const QS_MOUSEMOVE = &H2
Private Const QS_PAINT = &H20
Private Const QS_POSTMESSAGE = &H8
Private Const QS_TIMER = &H10
Private Const QS_MOUSE = (QS_MOUSEMOVE Or QS_MOUSEBUTTON)
Private Const QS_INPUT = (QS_MOUSE Or QS_KEY)
Private Const QS_ALLEVENTS = (QS_INPUT Or QS_POSTMESSAGE Or QS_TIMER Or QS_PAINT Or QS_HOTKEY)

Private Declare Function MsgWaitForMultipleObjects Lib "user32" (ByVal nCount As Long, pHandles As Long, ByVal fWaitAll As Long, ByVal dwMilliseconds As Long, ByVal dwWakeMask As Long) As Long

Private Declare Function CreateEvent Lib "kernel32" Alias "CreateEventA" (lpEventAttributes As SECURITY_ATTRIBUTES, ByVal bManualReset As Long, ByVal bInitialState As Long, ByVal lpName As String) As Long
Private Declare Function SetEvent Lib "kernel32" (ByVal hEvent As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Private hEvent(1) As Long
Private MyData(1) As String

Private Sub Command1_Click()
    Inet1(0).Execute "http://www.abc.com/", "GET"
    Inet1(1).Execute "http://www.xyz.com/", "GET"
    'Wait for 10 seconds
    MsgWait 10
    MsgBox MyData(0) & MyData(1)
    'process MyData(0) & MyData(1)
End Sub

Private Sub Inet1_StateChanged(Index As Integer, ByVal State As Integer)
    Select Case State

    Case icResponseCompleted
    On Error Resume Next
    Dim tmpData As String
    tmpData = Inet1(Index).GetChunk(1024, icString)
    While Len(tmpData) <> 0
        DoEvents
        MyData(Index) = MyData(Index) + tmpData
        tmpData = Inet1(Index).GetChunk(1024, icString)
    Wend
    'set event
    SetEvent hEvent(Index)

    'handle error
    Case icError
    SetEvent hEvent(Index)
    End Select
End Sub

'This routine waits for a specified time without blocking events
Private Function MsgWait(ByVal lngSec As Integer) As Long
    'This code creates an event
    Dim sd As SECURITY_ATTRIBUTES
    With sd
       .nLength = Len(sd)       'we pass the length of sd
       .lpSecurityDescriptor = 0
       .bInheritHandle = 0
    End With
    hEvent(0) = CreateEvent(sd, False, False, "MyEventNotification1")
    hEvent(1) = CreateEvent(sd, False, False, "MyEventNotification2")
   
   
    Dim WaitRet As Long
    Dim StartTime As Long
    '==Start wait loop==
    StartTime = CLng(Timer)
    Do Until Timer > StartTime + lngSec
        WaitRet = MsgWaitForMultipleObjects(2, hEvent(0), False, 100, QS_ALLEVENTS)
       
        Select Case WaitRet
        Case WAIT_TIMEOUT       'The first case must always be WAIT_TIMEOUT 'cause it is the most used option
            DoEvents            'until the shelled process terminates
        Case WAIT_FAILED Or WAIT_ABANDONED
            MsgBox "Wait failed or abandoned", vbExclamation
            Exit Do
        Case WAIT_OBJECT_0      'The first event got signaled so get out of the loop
            Exit Do
        Case WAIT_OBJECT_0 + 1  'The second event got signaled so get out of the loop
            Exit Do
        Case WAIT_OBJECT_0 + 2  'Other event
            DoEvents
        Case Else
            Debug.Assert False
        End Select
    Loop
    '==End wait loop==
   
    'Close event handle
    CloseHandle hEvent(0)
    CloseHandle hEvent(1)
   
    hEvent(0) = 0
    hEvent(1) = 0
    MsgWait = WaitRet
End Function

0
 
LVL 2

Expert Comment

by:saurabhgupta
ID: 8176726
This code will make 2 asnync requests and wait for both them to complete or 10 seconds, whichever is earlier. If you have difficulty understanding the code let me know.
I have used MsgWaitForMultipleObjects instead of Sleep API so that the events are not blocked.

Regards
Saurabh
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 8176953
hearing...
0
 

Author Comment

by:cMh
ID: 8181503
Thanks for all your help saurabhgupta!  This works great.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses
Course of the Month14 days, 7 hours left to enroll

770 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