[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

How to pass values from ActiveX Control to Standard exe

Posted on 2002-05-08
4
Medium Priority
?
155 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 400 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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 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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

656 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