|
-
Mar 17th, 2001, 02:03 AM
#1
Thread Starter
PowerPoster
I am having difficulties in calling an activex controls methods from a standard module which is in the same project. If I use the code written below, I get a run time error 91 ("Object variable or With Block Not set"). But if I use the the NEW keyword, it says "Invalid use of NEW Keyword"
Code:
Dim t as UserControl1
'the next line generates the error
t.MyMethod
-
Mar 19th, 2001, 02:00 PM
#2
New Member
Active X
You need to start a active x control project first. Then
after you save and start it you can add a standerd project to the list. Open it and in the toolbox on the right you will see the active x icon on the bottom. Click it
and paste on the from. Hope that helps
Glenn
Newbe to the Programming World, VB6.0, HTML, SQL7.0
In it for life.
-
Mar 20th, 2001, 08:56 PM
#3
Thread Starter
PowerPoster
I am talking about having the code being in a standard module of the same project.
-
Mar 21st, 2001, 02:43 AM
#4
Hyperactive Member
Think of the code in the standard modules as code to provide services to the aX control, not the other way around.
That said, you need to pass a reference of the control you wish to use to the code module (as a global reference, or function byref param).
Example: Global reference
Code:
'/ in standard module
Public g_oCtlRef As MyControl1
Public Sub DoSomething
'/
g_oCtlRef.MyMethod
'/
End Sub
'/ then on the control, you obviously have a method called MyMethod.
'/ And, when ever you wish to call your global function DoSomething from the control, you just set the g_oCtlRef to me, i.e.
Set g_oCtlRef = Me
You could also pass 'Me' as a param to DoSomething.
Hth.
td.
"One logical slip and an entire scientific edifice comes tumbling down." - Robert M. Pirsig
[email protected]
"but if Einstein is right and God is in the details, reality requires that we sometimes get religion." - Scott Meyers.
-
Mar 21st, 2001, 05:29 AM
#5
Thread Starter
PowerPoster
Would this even work if I needed the function is needed as a callback functionfor an api?(I am not on my computer so I cannot test it right now)
-
Mar 21st, 2001, 06:45 AM
#6
Hyperactive Member
err, what are you asking?
If you want to use a API Callback, then your callback function MUST be in a module.
td.
"One logical slip and an entire scientific edifice comes tumbling down." - Robert M. Pirsig
[email protected]
"but if Einstein is right and God is in the details, reality requires that we sometimes get religion." - Scott Meyers.
-
Mar 22nd, 2001, 01:42 AM
#7
Thread Starter
PowerPoster
I know that I need to have the callback function in the Module. My problem is that ow do I call a method of the control I have created from the module in which I have the callback function. If I use the code given by you, it would not accept declaring it as MyControl1. If I declare it as type UserControl, then it gives a type mismatch error when passing Me as param.
-
Mar 22nd, 2001, 03:45 AM
#8
Hyperactive Member
I presume you are making the api call from the control. In this case, all you do is set the global ref g_oCtlRef to Me, before you make the api call which sets the callback. The when the callback function calls you global proc, it has access to g_oCtlRef.
td.
"One logical slip and an entire scientific edifice comes tumbling down." - Robert M. Pirsig
[email protected]
"but if Einstein is right and God is in the details, reality requires that we sometimes get religion." - Scott Meyers.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|