Results 1 to 8 of 8

Thread: calling activex controls methods from a standard module

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    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

  2. #2

    Lightbulb 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.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    I am talking about having the code being in a standard module of the same project.

  4. #4
    Hyperactive Member tumblingdown's Avatar
    Join Date
    Mar 2000
    Posts
    362
    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.

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    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)

  6. #6
    Hyperactive Member tumblingdown's Avatar
    Join Date
    Mar 2000
    Posts
    362
    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.

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    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.

  8. #8
    Hyperactive Member tumblingdown's Avatar
    Join Date
    Mar 2000
    Posts
    362
    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
  •  



Click Here to Expand Forum to Full Width