VB Creating and getting data from textbox

Posted on 2014-09-19
Last Modified: 2014-09-20

Creating a new Textbox

dim txt as new
dim cnt as integer = 0

on a tabpage button Click event create the textbox


cnt = cnt + 1 =  = 25 = "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

Question by:Kevinfeening
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
  • 3
  • 2
LVL 12

Expert Comment

ID: 40334061
try txt.text

Author Comment

ID: 40334156
Thanks Tried that before I sent the question txt.text returns ""
LVL 12

Expert Comment

ID: 40334171
ok. Try this:
 enteredtext = Me.Controls(txt.Name).Text
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

LVL 15

Expert Comment

ID: 40334339
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
 dim cnt as integer = 0 

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 sub

Open in new window


Author Comment

ID: 40334795
Thanks for the ideas

I create the textbox

dim txt as new

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

LVL 12

Accepted Solution

ktaczala earned 500 total points
ID: 40334890
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"?

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

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

739 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