[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 302
  • Last Modified:

AsyncRead and a Form with ActiveX

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
scottg
Asked:
scottg
  • 4
  • 3
  • 2
  • +1
1 Solution
 
martiCommented:
Do you have a public method 'AsyncRead' for your UserControl declared? Does the parameters of that method match the ones you are passing?
0
 
scottgAuthor Commented:
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
 
lbkCommented:
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
Technology Partners: 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!

 
martiCommented:
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
 
scottgAuthor Commented:
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
 
lbkCommented:
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
 
scottgAuthor Commented:
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
 
fguerreiro_inixCommented:
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
 
martiCommented:
Scott, I can not post an answer. I have to reject the fguerreiro_inix's answer first.
0
 
martiCommented:
See above.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

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