Results 1 to 9 of 9

Thread: Main sub and UserControl

  1. #1

    Thread Starter
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Main sub and UserControl

    Is there any way to call a sub from UserControl from Main sub? Or do anything at all for the control? I tried UserControl.Sub_Name and UserControlsName.Sub_Name but with no luck...

    I'd also know something more about using the Main sub in an OCX / ActiveX, just some general information would be nice


    And I did a search on the forums and found nothing about this matter.

  2. #2
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Yes... be sure that the control is loaded, and the sub is Public.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  3. #3

    Thread Starter
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654
    I have the Main sub in the control (meaning, in a module), not the control on a form. I get a compile error when I try to do anything for the UserControl.

  4. #4
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629
    ParentForm.UserControlsName.Sub_Name

  5. #5

    Thread Starter
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654
    Have to make this clear: I'm making a control, not using one in a program.

  6. #6
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    I'm a little confused. Are we just talking any old sub in a module in your AX control project? If so, you'll need to make the sub in the module public, and also make a public "piggy back" sub in the usercontrol, so other projects can access it.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  7. #7

    Thread Starter
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654
    What do you mean by "piggy back"? I made the sub I wanted to call Public - it just doesn't help as I can't access the UserControl from the module at all.

  8. #8
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    By piggy back I meant that The outside world would call the method in the usercontrol, and that in turn would simply pass all the arguments it gets to the method in the module. And likewise with the return value (if any).

    As for accessing the usercontrol from the module, can't you just pass in a reference to the current instance? ie
    VB Code:
    1. 'In module
    2. Public Sub SayMyName(c As SomeUserControl)
    3.     MsgBox c.Name
    4. End Sub
    5.  
    6. 'In Usercontrol
    7. Public Sub CallSayMyName()
    8.     SayMyName Me
    9. End Sub

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  9. #9

    Thread Starter
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654
    Hmm, well I found a way to do the thing I wanted without using a Main sub to confuse my life. Then I found out the changes didn't help me at all: even by using API gettickcount to do animating on the UserControl, the animating stops if I ie. scroll something - before I used a timer. So...I'm stuck with the thing. I'd like to do animating but I must use DoEvents (which apparently is the one that causes animating to stop) or the control doesn't seem to work at all.

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