Solved

VB Creating and getting data from textbox

Posted on 2014-09-19
6
299 Views
Last Modified: 2014-09-20
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
0
Comment
Question by:Kevinfeening
  • 3
  • 2
6 Comments
 
LVL 12

Expert Comment

by:ktaczala
ID: 40334061
try txt.text
0
 

Author Comment

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

Expert Comment

by:ktaczala
ID: 40334171
ok. Try this:
 enteredtext = Me.Controls(txt.Name).Text
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 15

Expert Comment

by:ChloesDad
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 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
 

Author Comment

by:Kevinfeening
ID: 40334795
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
 
LVL 12

Accepted Solution

by:
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"?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

930 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

12 Experts available now in Live!

Get 1:1 Help Now