Solved

Using Internet Transfer Contol (or Alternative!)

Posted on 2003-10-30
9
157 Views
Last Modified: 2012-06-21
I am using the VB6 Internet Transfer Control Method OpenURL within a project of mine to lookup data from a legacy system via a HTTP based CLI.

This works fine, but sometimes the requests come too close together causing a runtime error because the previous request is still executing.

I have tried:

URL = "http://10.0.0.23/checkbl.asp?ticket=" & Ticket & "&pn=" & FNumber
Do While Internet.StillExecuting
  DoEvents
Loop
OPut = Internet.OpenURL(URL)

But the StillExecuting property often never returns to false, causing the code to get stuck.

How can I fix this, or is there a better approad altogether?
0
Comment
Question by:rpm
  • 3
  • 3
  • 2
9 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9651388
But OpenUrl method is not async, it doesn't return control to your program until finished. Are you using it in a timer event?
0
 
LVL 1

Author Comment

by:rpm
ID: 9652135
The events are triggered by user input on a form and can be quite close together (1 - 2 seconds apart.) If OpenURL is not async, how come I am getting errors that the previous request is still executing when I call OpenURL.

I am not using Execute at all in this code.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9652247
But you are answering yourself:
"The events are triggered by user input on a form and can be quite close together "

I think user never waits until full cycle is completed so he is calling openurl over and over again.
If you are using a button to call the code, try disabling it until openurl method returns.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9652275
There is a free ftp component you could use to transfer files instead of internet transfer control:
http://www.freevbcode.com/ShowCode.Asp?ID=1593

and

http://www.chilkat.com/
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 16

Expert Comment

by:JohnBPrice
ID: 9653731
Do this:

While Inet1.StillExecuting
    MsgBox "Not done yet"
    Exit Sub
Wend

And it will work.

Here is my opinion of what is happening.  It's because VB is not multi-threaded, but it is reentrant, e.g. you can interupt the process to do something else.  When the user clicks too fast on the control, Windows and VB interrupts the process (e.g. inet control) to send the new the input.  VB runs your loop:

Do While Internet.StillExecuting
 DoEvents
Loop

until the cows come home because the first inet is never allowed to finish until the second request is done.  DoEvents allows other inputs to be processed, which only makes matters worse.  Likewise you can't sleep because you only have one thread, and you will just sleep forever.  What you need to do is respond and get out of the second request, which is why the exit sub works.

If you have to queue up user requests, make subsequent calls (when inet is stillexecuting), put the request in a queue and then exit.  After each request, check the queue to see if new requests have been added.

John



0
 
LVL 16

Expert Comment

by:JohnBPrice
ID: 9653799
Another option is to prevent second requests in the first place, e.g. if you have Button1 which initiates the request, do

button1.enabled = false

URL = "http://10.0.0.23/checkbl.asp?ticket=" & Ticket & "&pn=" & FNumber
OPut = Internet.OpenURL(URL)

button1.enabled = true
0
 
LVL 1

Author Comment

by:rpm
ID: 9656634
Following from the advice given, I have tried to change my code accordingly.

Firstly I have created two Subs:

Private Sub PreInternet()

  Do While IntBusy.Caption = "1"
    DoEvents
  Loop
  IntBusy.Caption = "1"

End Sub

Private Sub PostInternet()

  IntBusy.Caption = "0"

End Sub

I have also blocked the triggering events whilst executing the code:

Me.MousePointer = vbHourglass
    If PN1.Text = "Home" Then
      HomePhoneC.Enabled = False
      HomePhoneN.Enabled = False
    End If
    If PN1.Text = "Work" Then
      WorkPhoneC.Enabled = False
      WorkPhoneN.Enabled = False
    End If
    If PN1.Text = "Mobile" Then
      MobilePhoneC.Enabled = False
      MobilePhoneN.Enabled = False
    End If
    If PN1.Text = "Alternate" Then
      AltPhoneC.Enabled = False
      AltPhoneN.Enabled = False
    End If
    If PN1.Text = "Fax" Then
      FaxC.Enabled = False
      FaxN.Enabled = False
    End If
    PN1.Enabled = False
    PN2.Enabled = False
    URL = "http://10.0.0.23/checkbl.asp?ticket=" & Ticket & "&pn=" & FNumber
    PreInternet
    OPut = Internet.OpenURL(URL)
    PostInternet
    HomePhoneC.Enabled = True
    HomePhoneN.Enabled = True
    WorkPhoneC.Enabled = True
    WorkPhoneN.Enabled = True
    MobilePhoneC.Enabled = True
    MobilePhoneN.Enabled = True
    AltPhoneC.Enabled = True
    AltPhoneN.Enabled = True
    FaxC.Enabled = True
    FaxN.Enabled = True
    PN1.Enabled = True
    PN2.Enabled = True
    Me.MousePointer = vbNormal

However I am still getting the code stuck in the PreInternet Sub.

What am I doing wrong now?
0
 
LVL 16

Accepted Solution

by:
JohnBPrice earned 250 total points
ID: 9657287
My guess is that something is still calling the subroutine despite your disabling the controls.

It looks like you can get to this routine from several places, yet the code only disables the control you came from, so that would allow the other controls to make new requests before the previous one is done.  Take out all the 'If PN1.Text = "xxxxx"' statements so you disable everything that could call the subroutine (just like you enable them all at the end).

What is PN1?  What do the N and C mean, i.e. What is HomePhoneN vs. HomePhoneC?

If the disable worked, you would never get into PreInternet with intbusy.caption = "1", indeed if you ever do call PreInternet with intbusy.caption ="1", that will cause it to hang, e.g. the loop in PreInternet will never work the way you intend.  Instead of the loop, you could put in a catch like this.

Private function PreInternet() as boolean

  If IntBust.Caption = "1" then
    Msgbox "Error: Attept to open URL before previous call is finished"
    PreInternet = false
  Else
    PreInternet = true
    IntBusy.Caption = "1"
  End If

End Sub

 and instead of just calling it, check the value, e.g.

    If PreInternet() then
      OPut = Internet.OpenURL(URL)
      PostInternet
    End If

Me, I would just do it inline in the procedure at the top before you go through the disable/enable, e.g.

Me.MousePointer = vbHourglass
  if Internet.stillexecuting Then
    'Double check to sure we are never called until previous call is done
    Msgbox "Error: Attept to open URL before previous call is finished"
  else
      'Prevent this getting called while it is running
      HomePhoneC.Enabled = False
      HomePhoneN.Enabled = False
      WorkPhoneC.Enabled = False
      WorkPhoneN.Enabled = False
      MobilePhoneC.Enabled = False
      MobilePhoneN.Enabled = False
      AltPhoneC.Enabled = False
      AltPhoneN.Enabled = False
      FaxC.Enabled = False
      FaxN.Enabled = False
      PN1.Enabled = False
      PN2.Enabled = False

      URL = "http://10.0.0.23/checkbl.asp?ticket=" & Ticket & "&pn=" & FNumber
      OPut = Internet.OpenURL(URL)

      HomePhoneC.Enabled = True
      HomePhoneN.Enabled = True
      WorkPhoneC.Enabled = True
      WorkPhoneN.Enabled = True
      MobilePhoneC.Enabled = True
      MobilePhoneN.Enabled = True
      AltPhoneC.Enabled = True
      AltPhoneN.Enabled = True
      FaxC.Enabled = True
      FaxN.Enabled = True
      PN1.Enabled = True
      PN2.Enabled = True
  End If
    Me.MousePointer = vbNormal
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now