Solved

An ActiveX control including a form.

Posted on 1998-07-25
9
171 Views
Last Modified: 2010-05-03
Both form1 and usercontrol1 are under project1 in VB5.

From form1, how to access a varible in usercontrol1? Do you think we should not add a form or module when design an ActiveX control? I found we can not simply treat usercontrol1 as a form.....
0
Comment
Question by:username1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 2

Expert Comment

by:lmorris
ID: 1466640
You're right. A usercontrol is not a form. If you want to pass variables, then you must create properties and pass your information via the properties. If you want to have the control do something, then you must create methods for the control.

Here's an example:

Create a usercontrol project. Place a textbox on the control then place this code in it.

Option Explicit

Public Property Get Value() As Variant
    Value = Text1.Text
End Property

Public Property Let Value(ByVal vNewValue As Variant)
    Text1.Text = vNewValue
End Property

My variable in the user control in this case is a textbox, but it could be anything.

Now add a standard exe project. Place the usercontrol on it and a command button, then place this code in the usercontrol:

Option Explicit

Private Sub Command1_Click()
    MsgBox UserControl11.Value
End Sub

Private Sub Form_Load()
    UserControl11.Value = "123-45-6789"
End Sub

So, to pass a variable, I call it's value property as I did in the form_load proecedure.

To retrieve a variable, I call it's value property as I did in the Command1_click event.

If you need anymore halp on this topic, you can email me at lmorris@netins.net
0
 

Author Comment

by:username1
ID: 1466641
Thank you lmorris.

Before we can discuss further, I should point out again that my question is:
How to access a varible in usercontrol1 from form1 which is in the same project as the usercontrol1.
So, there is no exe project!

Cheers.
0
 

Author Comment

by:username1
ID: 1466642
Hi lmorris,

I am sorry, but I got know the answer to day ;-(
I am going to reopen the quesion.
Thank you again.
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 6

Expert Comment

by:alamo
ID: 1466643
Could you explain your problem again, and explain why lmorris' answer doesn't solve it?

I understood your question  exactly as lmorris did, and I think he gave you a good answer.
0
 
LVL 2

Expert Comment

by:lmorris
ID: 1466644
It doesn't matter that you form is in the same project or not. You still have to create properties and methods by which the form will communicate with your control. The same restrictions apply with class modules.
0
 
LVL 8

Accepted Solution

by:
MikeP090797 earned 70 total points
ID: 1466645
You simply can't do it. A UserControl is more simular to a class then to a form, it has instances - it means you have to create an instance of the control, like to place it on a form so you can access it's variables. For instance, if you have a class named Class1, you can't do Class1.Var=X, you must create a variable of that type:
Dim C as class1
C.Var=X
The same thing happens with UserControls.

The bottom line is if you want to share variables between form and usercontrol, you must create a module and declare the variables as Public, to make them global through the project
0
 

Author Comment

by:username1
ID: 1466646
To lmorris:

I think i didn't explained my question clearly, sorry.
1. My form1 and usercontrol1 are in the same project, the one to design a control....so that was usercontrol1 instead of usercontrol11 :-)
2. I have also tried to access a public varible or a created property in usercontrol1 from form1 and without success. The reason has been point out by mikeP.

Cheers.
0
 

Author Comment

by:username1
ID: 1466647
To lmorris:
To alamo:

Thank you for your comment. Any further comments welcome :-)

I think i didn't explained my question clearly, sorry.

My form1 and usercontrol1 are in the same project, project1, the one to design a control. There was no instance of usercontrol1 yet....That is like declared a type but not yet doing dim the type. So, we can not assign any value to a member of the type :-)

Cheers.
0
 

Author Comment

by:username1
ID: 1466648
To MikeP:

Thank you very much for your answer and help.
BTW you look don't like ( you said The bottom line is ... ) create a module for holding the public variable in my case. That is what I am doing :-(
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question