Solved

How to pass values from ActiveX Control to Standard exe

Posted on 2002-05-08
4
152 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
[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
  • 2
4 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 6995915
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
ID: 6995950
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
ID: 6996011
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
ID: 6996032
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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…

696 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