Solved

AsyncRead and a Form with ActiveX

Posted on 1998-05-04
10
269 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
Industry Leaders: 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 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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 process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

730 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