Create a textbox from a variable

rflorencio
rflorencio used Ask the Experts™
on
Hi,

This is not correct, but how can create a textbox for ex. from a variable, somethig like:

            Dim xx As String
            Dim xx As New TextBox()

best regards
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Fernando SotoRetired
Distinguished Expert 2017

Commented:
Hi rflorencio;

This is not possible to do. What do you need to do that needs this type of requirement?
Not sure I understood correctly, but probably
Dim s = "Hello World!"
Dim x As New TextBox With {.Text = s, .Visible = True, .Location = New Point(20, 20), .Width = 200}
Me.Controls.Add(x)

Open in new window

Author

Commented:
Hi,

I have some "parameters", like startdate, enddate, prductid for ex. to generate reports. But sometimes i only need for ex. startdate and enddate, others only productid, others all them. I alread done a code to generate controls in runtime mode. But my goal is read the "parameter" for ex. startdate and create a textbox control called startdate to get date, etc ...

best regards

Author

Commented:
I get it.
Top Expert 2015

Commented:
You usually create controls dynamically when you do not know beforehand how many controls you coudl need. As an example, if I have a form that has buttons to print reports, and I cannot know when I build application how many reports will be available. This could be done with the technique described by Ark.

In your case however, you know how many controls you might need. In such a situation, it is usually better to create your form as you would, with all the possible controls, but set the the Visible or Enabled property of those that might not be needed to False. The controls are in the form, but the user sees them as inactive (Enabled) or does not see them (Visible).

When, when you need to display information in these controls, simply reset the property to True so that it is activated or visible.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial