Looping through a bunch of text boxes

  • Thread starter Thread starter Edward
  • Start date Start date
E

Edward

VB.NET

I have a bunch of textboxes on my form

txtPart1
txtPart2
....
txtPart16

When the user presses "Ok", I need to concatenate the values into a
single string and paste it into an email.

I wondered about this (AIR CODE):

Dim strParts As String
Dim iintIndex As Integer

For iintIndex = 1 To 16 Step 1
strParts &= Me.txtPart & iintIndex.ToString.Text
Next

Is something like this possible? I realise the above is syntactically
incorrect, by the way!

TIA

Edward
 
Hi Edward,

There are a lot of posibilities,

This is one that I find at this moment the nicest.
(This sample delete the spaces in front and end in textbox1 and textbox2).

I hope this helps?

\\\
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim txtboxarea As TextBox() = New TextBox() {TextBox1, TextBox2}
For Each txt As TextBox In txtboxarea
AddHandler txt.LostFocus, AddressOf TextBox_LostFocus
Next
End Sub
Private Sub TextBox_LostFocus(ByVal sender As Object, _
ByVal e As System.EventArgs)
DirectCast(sender, TextBox).Text = _
Trim(DirectCast(sender, TextBox).Text)
End Sub
///
Cor
 
Dim fullString as String
For each ctrl as Control in me.Controls
If TypeOf(ctrl) is TextBox Then
fullString += ctrl.Text
End If
End For

HTH

Rigga.
 
* (e-mail address removed) (Edward) scripsit:
I have a bunch of textboxes on my form

txtPart1
txtPart2
...
txtPart16

When the user presses "Ok", I need to concatenate the values into a
single string and paste it into an email.

\\\
Dim atxt() As TextBox = {TextBox1, ..., TextBox16}
Dim txt As TextBox
For Each txt In atxt
...
Next txt
///
 
VB.NET

I have a bunch of textboxes on my form

txtPart1
txtPart2
...
txtPart16

When the user presses "Ok", I need to concatenate the values into a
single string and paste it into an email.

I wondered about this (AIR CODE):

Dim strParts As String
Dim iintIndex As Integer

For iintIndex = 1 To 16 Step 1
strParts &= Me.txtPart & iintIndex.ToString.Text
Next

Is something like this possible? I realise the above is syntactically
incorrect, by the way!

TIA

Edward

All excellent suggestions - many thanks!

Edward
 
Back
Top