Reputation: 303
I have a form that has 3 Tabs and a user will populate dropdowns on the form and then press save.
I then write the string to a text file with a separator between each answer, is there a better way of doing it other than what I have done below?
Dim tesstring As String = " test " & _
Separator & _
answer1 & _
Separator & _
answer2 & _
Separator & _
answer 3 & _
Separator & _
answer4 & _
Separator & _
answer5 & _
Separator & _
Combo_BS.SelectedItem.ToString.Substring(0, 6) & _
Separator & _
answer6 & _
Separator & _
answer7 & _
Separator & _
answer8 & _
Separator & _
answer9 & _
Separator & _
answer10 & _
Separator & _
answer11 & _
Separator & _
answer12 & _
Separator & _
answer13 & _
Separator & _
answer14 & _
Separator & _
answer15 & _
Separator & _
answer16 & _
Separator & _
answer17 & _
Separator & _
answer18 & _
vbCrLf
Upvotes: 1
Views: 2868
Reputation: 20469
To expand on Jon's answer, create a collection of answers. For example, if all the answers are in textboxes in a panel called 'Panel1':
Dim answers = From x In Me.Panel1.Controls.OfType(Of TextBox)() Select x.Text
Dim tesstring As String = String.Join(Separator, answers)
Upvotes: 0
Reputation: 1503290
is there a better way of doing it other than what I have done below?
Yes. Create an array of all the values, and then use String.Join
:
Dim tesstring As String = String.Join(Separator, values) & vbCrlf
Ideally, don't have 18 different answer
variables to start with - can't those be in a collection?
Upvotes: 3