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.
Re: User Control Public/Private
Post code I will look at it.
1 Attachment(s)
Re: User Control Public/Private
The code is quite simple (at this point)...
VB Code:
Private Sub txtMyBox_LostFocus()
txtMyBox.Tag = txtMyBox.Text & "Test"
End Sub
I have also attached the ctl file, so you can see that...
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.
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:
Private Sub ucMyBox1_LostFocus()
MsgBox (ucMyBox1.Tag), vbInformation
End Sub
Thanks for you help.
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.
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:
Private Sub ucMyBox1_LostFocus()
MsgBox (ucMyBox1.Tag), vbInformation
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.
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.
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!