Solved

AsyncRead and a Form with ActiveX

Posted on 1998-05-04
10
249 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
  • 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…

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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now