Results 1 to 4 of 4

Thread: Calling methods of .ocx controls at runtime

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2009
    Posts
    2

    Lightbulb Calling methods of .ocx controls at runtime

    Hi,
    I wanted to load the .ocx controls at runtime and call its methods during runtime.
    I was able to load the control at runtime but not able to set its methods and subroutines.
    Here is the code snippet:

    Dim WithEvents objEcg As VBControlExtender
    Private Sub Form_Load()
    Set obj = Controls.Add("ProgID.OCXCtrl", "ocx1", Frame1)
    obj.Visible = True
    obj.WebURL = "URLPath"
    obj.Height = 375
    obj.Left = 120
    obj.Top = 240
    obj.Width = 300
    Call obj.methodOnOCX("strparam1", "strparam2")
    End Sub

    Note: methodOnOCX is a subroutine with signature as methodOnOCX(str1 as String,str2 as String)

    Error on calling the function is: "Object variable or with block variable not set"

    Note: I am able to set all the properties of the control and view them during runtime.

    Any help is appreciated.
    Thanks

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Calling methods of .ocx controls at runtime

    Is methodOnOCX a Public method? Private & Friend declarations should fail. Additionally, if it is public, are you sure the error is coming from that call or could the error be coming from within the OCX? That may be a possibility.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2009
    Posts
    2

    Re: Calling methods of .ocx controls at runtime

    No, the method is a public method. If the ocx control is added during runtime itself, the method runs fine. So, I don't think there is any error in the method.

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Calling methods of .ocx controls at runtime

    Sorry it took a bit. I think this might work. precede your methods with the word Object, like so....

    Call obj.Object.methodOnOCX("strparam1", "strparam2")
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

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