VB Creating and getting data from textbox

Hi

Creating a new Textbox

dim txt as new system.windows.forms.textbox
dim cnt as integer = 0

on a tabpage button Click event create the textbox

tabpage.controls.Add(txt)

cnt = cnt + 1
txt.top =  = 25
txt.name = "TextNam" & cnt.tstring

Then the user enters some text in the textbox

How do I find the user entered text for TxtNam1.text

as trying the below
 
Dim enteredtext as string
enteredtext = txtName1.text

shows txtName1 not declared

Thanks
KevinfeeningAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ktaczalaCommented:
try txt.text
0
KevinfeeningAuthor Commented:
Thanks Tried that before I sent the question txt.text returns ""
0
ktaczalaCommented:
ok. Try this:
 enteredtext = Me.Controls(txt.Name).Text
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

ChloesDadCommented:
The best way would be to add a handler to the lostfocus event of the text box after it is created, then in the event handler you can read the .text property


' I would put all this inside the click event of the tab page

 dim txt as new system.windows.forms.textbox
 dim cnt as integer = 0 
 tabpage.controls.Add(txt)

AddHandler txt.LoftFocus, AddressOf TextBox_LostFocus

Open in new window


Then create a new method

Private Sub TextBox_LostFocus(sender as object, e as eventargs)

dim SendingTextBox as textbox
dim TextBoxText as string

SendingTextBox = trycast(sender,textbox)

IF not sendingtextbox is Nothing then ' this should never be nothing unless you have added this handler to a non-text box
  textboxtext = SendingTextBox.text
END IF

End sub

Open in new window

0
KevinfeeningAuthor Commented:
Thanks for the ideas

I create the textbox

dim txt as new system.windows.forms.textbox
tabpage.controls.Add(txt)

Then using a table to find the name they want to use in the Label Caption I create as well as the textbox.
So it could be Name of staff for the label Caption and I remove the spaces and use NameOfStaff as the textbox Name

First suggestion
enteredtext = Me.Controls(txt.Name).Text then gives an error -

Object referenced not set to an instance of an object

Second Suggestion
AddHandler txt.LoftFocus, AddressOf TextBox_LostFocus

Name TextBox_LostFocus is not declared

Thanks
0
ktaczalaCommented:
OK, that's because you're adding the textbox to the tab control, but calling it from somewhere other than the code behind the tab control.
Try this.
enteredtext = tabpage.Controls(txt.Name).Text

Is your tabpage control named "tabpage" or "tabpage1"?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.