Solved

Writing text in a textbox

Posted on 2000-05-02
12
298 Views
Last Modified: 2010-05-02
I have a usercontrol with a textbox on it. In the same project also is a
form. Now I want to write values which are created on the form to the
textbox on the usercontrol. Now the problem is, the form don´t know the
usercontrol or the textbox on it. Please write me a solution for this problem.

The form is in the same project. I already know how to add properties to a usercontrol. But this is not
the problem here. For example:
The Usercontrol has the name "ctlVisual" how could a form "talk" to the usercontrol. I don´t think
on the form on which the usercontrol is placed by the programmer...

I think these anwers are all ok,  but my usercontrol is not on the Form.
The form is not a second project on which the control is droped. If the control
is placed on the form i can get access by the properties, ok.
For example:
Instance_of_control.Property = "something"
But the control should comunicate with the form without being placed on it.
It is part of the usercontrol-project. Maybe Events can solve this problem.
What Do you think.
Alpha
0
Comment
Question by:_alpha
  • 4
  • 3
  • 2
  • +2
12 Comments
 
LVL 10

Expert Comment

by:caraf_g
Comment Utility
The form *must* know the user control. It need not know the text box.

In your user control code:

Public Property Let MyTextBoxesText(strNewValue As String)

'...usual user control property code
TheTextBoxOnTheControl.Text = strNewValue

End Property
Public Property Get MyTextBoxesText() As String

'...usual user control property code
MyTextBoxesText =TheTextBoxOnTheControl.Text

End Property


Put one of your user controls on the form

To set the text box's text, for example

YourUserControl1.MyTextBoxesText = "hello world"

etceterahr...
0
 
LVL 10

Expert Comment

by:caraf_g
Comment Utility
The "MyTextBoxesText" property will also be available in the properties window in design mode.

Use the property bag

Check out the ActiveX Control Interface Wizard. It makes it very easy to start with a new control if you want to propagate some properties of embedded controls to the outside world. Well worth investigating. It also provides a lot of the standard code, e.g. the code needed to use the property bag properly... use it for inspiration and to learn coding UserControls quickly.

Don't rely too much on it after the initial stages of coding a user control.
0
 
LVL 43

Expert Comment

by:TimCottee
Comment Utility
ON the add-ins menu should be the activex control interface wizard, you need to add a property "Text" which is mapped to the .Text property of the textbox contained within your control. Then when you place it on your form, the UserControl will be something like

UserControl11, you can set the text using:

UserControl11.Text = "Hello This is Text"
0
 
LVL 43

Expert Comment

by:TimCottee
Comment Utility
caraf_g, you beat me to it!
0
 

Author Comment

by:_alpha
Comment Utility
Edited text of question.
0
 
LVL 2

Expert Comment

by:mflam
Comment Utility
NO NO NO!
You don't need to do this!
You simply make the textbox the size you want,
and set the textbox's property:
MULTILINE
to TRUE.
and set the textbox's property:
SCROLLBAR
to 2 - Verticle.

That's all.

Now to get the "form" to know the text of the textbox,
add a property (set and get):
(Be in the code view, and press the menu:
 Tools/Add Procedure
 In the dialog that opens, choose the "Propery" radio,
 and in the textbox enter: Text.

Now you usercontrol (frame) has a property called: "text".
In the GET, you return the text from the textbox.
I will give you an example using "MYTEXT" as the property, change it to TEXT in your real app.
Example:
Public Property Get MYTEXT() As Variant
  MYTEXT = myTextbox ' short for: myTextbox.text
End Property
 
and in the LET (when you set the prop's value) have the textbox reflect this:
Public Property Let MYTEXT(ByVal vNewValue As Variant)
  myTextbox = MYTEXT ' same as myTextbox.text =...
End Property

Last but not least when the control initializes,
(first time around)
you want it to have the textbox set to the property:
mouse to the top left corner of the code view.
choose the usercontrol (or whatever name you changed it to):
 and on the right top corner choose the "initialize"
event (it's probably the default):
Now you should have written in your VB:
Private Sub UserControl_Initialize()
End Sub

That's it.
Youre next question will be:
How do I change the usercontrol's name,
and how do I change the project's name,
so I get what I want in the registry....

Good luck, Moshe
 
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 10

Expert Comment

by:caraf_g
Comment Utility
Moshe,

Interesting comment:

"NO NO NO, you don't need to do this, do *THIS* instead"
After which you basically repeat what I was saying in different words.

<smile>
0
 
LVL 1

Expert Comment

by:4P
Comment Utility
Hi Alpha,

if I understand you right, your big problem is that you have two forms in a project. One form has the usercontrol with the textbox, but you want the other form to communicate with the user control.

First of all, everybody was right about you have ot create a property so that the text in the textbox is accessible outside the usercontrol.

To make the other form get or set the property, simply use the name of the form on which the usercontrol is. For example, if the form is named CtrlCont, the control is Ctrl1, and the property is Text, then use CtrlCont.Ctrl1.Text="Whatsoever...". Note this will not work if you load the form with the New keyword; if that's the case then you should use the name of your varibale to which the form is loaded instead of the name of the form (which is really a class name).

Hope this is what you were looking for.
0
 

Author Comment

by:_alpha
Comment Utility
Edited text of question.
0
 
LVL 1

Accepted Solution

by:
4P earned 100 total points
Comment Utility
OK, I see. So your form in the UserControl project, and you want it to send data back to the control itself, and because this is the UserControl project, the control is not yet placed on any form.

Here is the solution:

You still need the property as discussed before.

Add a Bas module to your UserControl project, and declare a Public variable in it as Object, for example:
Public CtrlObject as Object.

Then, in the Initialize event of your UserControl, put:
Set CtrlObject=Me

In the Terminate event, put:
Set CtrlObject=Nothing

From that on your form can use the CtrlObject to set any properties of the control.

CtrlObject.Text="WhatSoEver..."
0
 
LVL 10

Expert Comment

by:caraf_g
Comment Utility
"But the control should comunicate with the form without being placed on it."

No can do.

A control needs to have a parent.
0
 

Author Comment

by:_alpha
Comment Utility
Thanks Pèter,

thats what I have been looking for. I know my english is not perfect, so I sometime have problems to explain my problems.

Thank You for your efforts.

Bye
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

728 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