String.Concat(?, ?) Help please.

T

Trint Smith

Ok,
I have a webform that has these checkboxes:

1. something
2. something else
3. and something else

When the user clicks on the checkbox, I want all of the selections to go
into a textbox if all are checked. But currently, just the last
selection is going in. Here's the code I have:

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click
If CheckBox1.Checked = True Then
TextBox6.Text = String.Concat(SPString, SPString1)
End If
If CheckBox2.Checked = True Then
TextBox6.Text = String.Concat(SPString, SPString2)
End If
If CheckBox3.Checked = True Then
TextBox6.Text = String.Concat(SPString, SPString3)
End If
End Sub

Any help is appreciated.
Thanks,
Trint


.Net programmer
(e-mail address removed)
 
J

Jay B. Harlow [MVP - Outlook]

Trint,
Have you tried something like:

TextBox6.Text = SPString
If CheckBox1.Checked = True Then
TextBox6.Text = String.Concat(TextBox6.Text, SPString1)
End If
If CheckBox2.Checked = True Then
TextBox6.Text = String.Concat(TextBox6.Text, SPString2)
End If
If CheckBox3.Checked = True Then
TextBox6.Text = String.Concat(TextBox6.Text, SPString3)
End If

Depending on what SPString really is, you may need it with each
String.Concat.

Also I find it "cleaner" to use the concatenation operator "&" instead of
String.Concat. Remember the concatenation operator uses String.Concat
internally so there is no performance gain or loss to use &.

Plus in this case I would consider using concatenation assignment "&="
instead of just &.

TextBox6.Text = SPString
If CheckBox1.Checked = True Then
TextBox6.Text &= SPString1
End If
If CheckBox2.Checked = True Then
TextBox6.Text &= SPString2
End If
If CheckBox3.Checked = True Then
TextBox6.Text &= SPString3
End If

Note these two lines are the same:

TextBox6.Text = TextBox6.Text & SPString1

TextBox6.Text &= SPString1

Hope this helps
Jay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top