Solved

How to pass values from ActiveX Control to Standard exe

Posted on 2002-05-08
4
144 Views
Last Modified: 2010-05-02
I've just created a simple ActiveX, say, UserControl1 by using VB 6 sp5, and then I registered the ocx file by using regsrv32.

Next, I created a new EXE project and then add that ActiveX with three textfields namely TextBox1, TextBox2 and TextBox3. Finally, I created three textfields on my newly EXE project, namely txtTextBox1, txtTextBox2 and txtTextBox3 and a button.

After clicking the button, the values of the textfields on the ActiveX Control will be copied to those on the EXE one, say,

txtTextBox1.Text = TextBox1.Text
txtTextBox2.Text = TextBox2.Text
txtTextBox3.Text = TextBox3.Text

But, what's the syntaxt then? After I typed "UserControl1", I couldn't see any TextBox1, TextBox2, TextBox3 on the selection.

Thanks for the help!
0
Comment
Question by:mscproj
  • 2
4 Comments
 
LVL 43

Expert Comment

by:TimCottee
Comment Utility
You haven't created any properties that are exposed to the container application. There is an add-in activex control wizard that will automate some of this for you. I would suggest that as you are starting with this you use the wizard to create the properties and link them to the underlying properties of the controls that you have placed in the usercontrol. Then examine the resulting code to understand how properties can be employed to do this. The simplest property method(s) would be something like this:

Public Property Let TB1(ByVal TBText As String)
  Textbox1.Text = TBText
End Property

Public Property Get TB1() As String
  TB1 = Textbox1.Text
End Property

0
 

Expert Comment

by:HeN_da_MaN
Comment Utility
Don't forget to use the Usercontrol_ReadProperties and
Usercontrol_WriteProperties, there you can store and retrieve the values in the PropertyBag, which means you don't lose the values after closing the project, maybe not necessary in this case though.
0
 

Author Comment

by:mscproj
Comment Utility
Yes, I see. But, if I create the ActiveX control, and want to build a simple exe project that has two that ActiveX Control.

After I enter the values on the three textfields on 1st ActiveX Control, then enter a button, it will update those three textfields on 2nd ActiveX Object.

Also, after I change the valueson the three textfields on the 2nd ActiveX Control, then enther another button, it will update those three textfields on the 1st Active Object.

How to write the coding the those two button events?

I've written something like


Private Sub CommandButton1_Click()
   MainControl2_getText1 (MainControl1.getText1)
   MainControl2_getText2 (MainControl1.getText2)
   MainControl2_getText3 (MainControl1.getText3)
End Sub

Private Sub CommandButton2_Click()
   MainControl1_getText1 (MainControl2.getText1)
   MainControl1_getText2 (MainControl2.getText2)
   MainControl1_getText2 (MainControl2.getText3)
End Sub


My ActiveX Control is something like this:

Public Property Get getText1() As String
   getText1 = TextBox1.Text
End Property

Public Property Let getText1(ByVal vNewValue As String)
   TextBox1.Text = vNewValue
End Property

Thanks again!
0
 
LVL 43

Accepted Solution

by:
TimCottee earned 100 total points
Comment Utility
Actually it would be:

Private Sub CommandButton1_Click()
  MainControl2.getText1 = MainControl1.getText1
  MainControl2.getText2 = MainControl1.getText2
  MainControl2.getText3 = MainControl1.getText3
End Sub

Private Sub CommandButton2_Click()
  MainControl1.getText1 = MainControl2.getText1
  MainControl1.getText2 = MainControl2.getText2
  MainControl1.getText2 = MainControl2.getText3
End Sub

As a property is assigned using the = operator e.g., PropertyName = PropertyValue as with the intrinsic properties of objects.

You can also simplify this slightly using a with .. end with block:


Private Sub CommandButton1_Click()
  With MainControl2
    .getText1 = MainControl1.getText1
    .getText2 = MainControl1.getText2
    .getText3 = MainControl1.getText3
  End With
End Sub

Private Sub CommandButton2_Click()
  With
    .getText1 = MainControl2.getText1
    .getText2 = MainControl2.getText2
    .getText2 = MainControl2.getText3
  End With
End Sub

This reduces the number of times that VB has to resolve the property of the object as it already gains a reference to the main object in the With statement and can then identify all properties and methods of that object without having to do this in each subsequent line. In some circumstances this can increase processing speed and is a recommended practice where possible.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

762 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now