Solved

AsyncRead and a Form with ActiveX

Posted on 1998-05-04
10
273 Views
Last Modified: 2008-02-01
I have a simply UserControl the calls AsyncRead(?,?,?) and downloads a text file from a web server and it works fine.

I then have the UserControl open a Form with

Form1.Show vbModal

And a form is displayed.  I then have a button on the form that does the following...

Private Sub Command1_Click()
   On Error Goto ErrorHandler  

   AsyncRead "http://whatver.com/text.txt, AsyncType, "NameHere"
   ' Or UserControl1.AsyncRead "http://whatver/text.txt, AsyncType, "NameHere"

ErrorHandler:
   MsgBox("Error in AsyncRead")
End Sub

But this will never start the download of the text.txt file.  
I can only get the text file to download when the AsyncRead is called from a Sub within the UserControl.  As soon as call AsyncRead from the form, it always jumps to ErrorHandler.

Anyone?  How can I call AsyncRead from a vbModal form???

Thanks.  I'm hoping to get an example.
0
Comment
Question by:scottg
[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
  • 2
  • +1
10 Comments
 
LVL 2

Expert Comment

by:marti
ID: 1439069
Do you have a public method 'AsyncRead' for your UserControl declared? Does the parameters of that method match the ones you are passing?
0
 

Author Comment

by:scottg
ID: 1439070
No, its not offically declared, but its automatically available, and works fine from the UserControl, but not from a form.  

Example:

Private Sub UserControl_Click()
   On Error GoTo ErrorTrap
   AsyncRead "http://site/text.txt", vbAsyncTypeFile, "test"
   GoTo Complete

ErrorTrap:
   MsgBox ("Error with Asyncread")

Complete:
   MsgBox ("Asyncread probably worked")
End Sub

This works fine, because asyncread called from a SUB within the usercontrol.  But if it opens a form instead...

Private Sub UserControl_Click()
   Form1.Show vbModal
End Sub

and has the form with a button that does the above AsyncRead;
will not work and always jumps to the error.

Any idea?  I'll forward you some cash if you can figure it out.

Thanks.

0
 
LVL 1

Expert Comment

by:lbk
ID: 1439071
In you error handler use

ErrHandler:
  MsgBox Err.Description
end sub

and tell me what the error message is.
AsynchRead might try to display another form, and that's not allowed when a modal form is showing.
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 2

Expert Comment

by:marti
ID: 1439072
Scott,
Declare a public method of your UserControl say StartLoading. Put your code
    AsyncRead "http://site/text.txt", vbAsyncTypeFile, "test"
in that method.
On Command1_Click event of the command button type:
    UserControl11.StartLoading
to call that method.
And that's it. If you have problems I'll send you a sample.
0
 

Author Comment

by:scottg
ID: 1439073
On Error GoTo ErrorTrap
UserControl1.AsyncRead "http://site/text.txt", vbAsyncTypeFile, "Name"
Goto Compelete:

ErrorTrap:
   MsgBox Err.Description
   
Complete:
   MsgBox ("Asyncread probably worked")
   
If the above is called from a command butotn on the modal form , it reports "Object Required".  I don't think I'm properly referencing AsyncRead within the UserControl.   Or AsyncRead isn't available to the form for some reason.  Is there something I should have Declared?  


marti:
>If you have problems I'll send you a sample.

If you actually have a small example that would be great.  My address is scottg@niagara.com.  I tried what you mentioned before, and kept getting "Runtime Error 424, Object Required".  I don't think I was doing it properly.  If you could, possibly E-Mail anything you have?  Thanks.

Scott.
0
 
LVL 1

Expert Comment

by:lbk
ID: 1439074
Can you run this project within VB, or only in EXE format?

If you can, set Error trapping to Always Break on errors. It will then stop right at this line. When it does, highlight UserControl1 and hit <shift><F9>. If the dialogue shows <NOTHING> under value, the usercontrol you are referencing does not exist. Otherwise, add the control-project (File>Add Project> and make sure that you have error trapping set to Always Break in that project as well. It should then stop as close to the error as possible, and you can see what the variable is you didn't set, or whatever else causes the trouble
0
 

Author Comment

by:scottg
ID: 1439075
I got it working now with marti's example.  I had to mount a separate usercontrol onto the modal form and reference that one, not the UserControl1 directly.  This is probably obvious to you, but I'm too inexperienced to see that yet.

Thank for your help though.  
0
 
LVL 3

Expert Comment

by:fguerreiro_inix
ID: 1439076
Hello SCOTTG

AsyncRead only works with user controls. if you use
(AsyncRead "http://site/text.txt", vbAsyncTypeFile, "test" )
on click of a button on a form a error ocurs because
the current object is the form (and the form doesn't have that method). You  must use (UserControlName.AsyncRead "http://site/text.txt", vbAsyncTypeFile, "test" )

Hope this helps


0
 
LVL 2

Expert Comment

by:marti
ID: 1439077
Scott, I can not post an answer. I have to reject the fguerreiro_inix's answer first.
0
 
LVL 2

Accepted Solution

by:
marti earned 200 total points
ID: 1439078
See above.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

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…
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.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

707 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