Results 1 to 9 of 9

Thread: User Control Public/Private

  1. #1

    Thread Starter
    Hyperactive Member VB4fun's Avatar
    Join Date
    May 2003
    Location
    too far from Fiji
    Posts
    342

    User Control Public/Private

    I am trying my first user control, but after I save it as an .ocx and try to add it to my project, it tells me the control can not be used as a public and is changing it to private.

    Can anyone explain this to me?

    It is a really simple text box that takes the entry and sets the tag property to the text(modified) in the box.
    Talk does not cook rice.
    -Chinese Proverb

  2. #2
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961

    Re: User Control Public/Private

    Post code I will look at it.
    Nobody knows what software they want until after you've delivered what they originally asked for.

    Don't solve problems which don't exist.

    "If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)

    2 idiots don't make a genius.

  3. #3

    Thread Starter
    Hyperactive Member VB4fun's Avatar
    Join Date
    May 2003
    Location
    too far from Fiji
    Posts
    342

    Re: User Control Public/Private

    The code is quite simple (at this point)...
    VB Code:
    1. Private Sub txtMyBox_LostFocus()
    2.     txtMyBox.Tag = txtMyBox.Text & "Test"
    3. End Sub

    I have also attached the ctl file, so you can see that...
    Attached Files Attached Files
    Talk does not cook rice.
    -Chinese Proverb

  4. #4
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961

    Re: User Control Public/Private

    Start a new EXE project. Then add the control. You will be able to use it from the Form or whatever. VB will change it from Public to Private because of the type of project.

    The only time you will have a Public control is if you are making a project of type OCX.
    Nobody knows what software they want until after you've delivered what they originally asked for.

    Don't solve problems which don't exist.

    "If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)

    2 idiots don't make a genius.

  5. #5

    Thread Starter
    Hyperactive Member VB4fun's Avatar
    Join Date
    May 2003
    Location
    too far from Fiji
    Posts
    342

    Re: User Control Public/Private

    ok,
    then I guess my questions are this...

    What is the difference?

    How do I add it, if I want to make it public?

    When I start a new project, add this control (as private), and add the following code...I get a blank message box?
    VB Code:
    1. Private Sub ucMyBox1_LostFocus()
    2.     MsgBox (ucMyBox1.Tag), vbInformation
    3. End Sub

    Thanks for you help.
    Talk does not cook rice.
    -Chinese Proverb

  6. #6
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961

    Re: User Control Public/Private

    Well if you make a project of type OCX then VB expects you will have at least 1 .ctl file in the project. When you compile the object, and then make it binary compatible, other applications can ask the COM engine to deliver a running instance to its process space.

    For all that to work, it needs to be public.

    The consuming application can be of type Standard EXE. In this case, it can either add it as a binary component, or as a source code component. If you load the .CTL in the project as source code, the IDE makes it Private because it is not going to advertise its availability from an EXE project.

    That would only happen from an OCX type project.
    Nobody knows what software they want until after you've delivered what they originally asked for.

    Don't solve problems which don't exist.

    "If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)

    2 idiots don't make a genius.

  7. #7
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961

    Re: User Control Public/Private

    Quote Originally Posted by VB4fun
    ok,
    then I guess my questions are this...

    What is the difference?

    How do I add it, if I want to make it public?

    When I start a new project, add this control (as private), and add the following code...I get a blank message box?
    VB Code:
    1. Private Sub ucMyBox1_LostFocus()
    2.     MsgBox (ucMyBox1.Tag), vbInformation
    3. End Sub

    Thanks for you help.
    Yes, the .Tag will be blank. I don't know if you can access that Property from within the .CTL code. You are better off exposing your own custom Public Property. I did the same thing when making a PLC OCX wrapper. Instead of my consumer accessing the .Tag property, I made a .TagName Property which my consumer could write to, and I could read from.
    Nobody knows what software they want until after you've delivered what they originally asked for.

    Don't solve problems which don't exist.

    "If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)

    2 idiots don't make a genius.

  8. #8

    Thread Starter
    Hyperactive Member VB4fun's Avatar
    Join Date
    May 2003
    Location
    too far from Fiji
    Posts
    342

    Re: User Control Public/Private

    Thanks, for your help.

    This sounds like it is going to take some research and tutorials, to complete what I am looking for....

    google, here I come....

    thanks again.
    Talk does not cook rice.
    -Chinese Proverb

  9. #9
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961

    Re: User Control Public/Private

    Quote Originally Posted by VB4fun
    Thanks, for your help.

    This sounds like it is going to take some research and tutorials, to complete what I am looking for....

    google, here I come....

    thanks again.
    I highly recommend this book - it has the most thourough chapter on OCX creation of any VB6 book I have ever read:

    "Programming Visual Basic 6.0", Microsoft Press, Balena. ISBN: 0-7356-0558-0. Go out and buy it tonight!
    Nobody knows what software they want until after you've delivered what they originally asked for.

    Don't solve problems which don't exist.

    "If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)

    2 idiots don't make a genius.

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