我有2个列表框。 listbox1包含可变帐户名,
John
James
Matt
第二个列表框包含一个非变量脚本
Dear <account name>
Thank you for contacting us.
We will get back to you soon.
我将通过帐户名称循环。我有代码。 但是如何在第3个列表框或文本框中获得输出,如下所示;
Dear John
Thank you for contacting us.
We will get back to you soon.
Dear James
Thank you for contacting us.
We will get back to you soon.
Dear Matt
Thank you for contacting us.
We will get back to you soon.
答案 0 :(得分:1)
我不确定您为什么使用ListBox作为静态文本,但此代码应该按照您希望的方式执行。
我正在使用For Each
遍历两个Listbox的Object Collections,将结果对象转换为字符串,然后将修改后的行添加到List(Of String),然后将其分配给TextBox的Lines属性。看看这是否适合你。
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim result As List(Of String) = New List(Of String)
For Each item As Object In ListBox1.Items
For Each line As Object In ListBox2.Items
result.Add(CStr(line).Replace("<account name>", CStr(item))) 'Modify line and add to List
Next
result.Add("") 'Add seperator
TextBox1.Lines = result.ToArray() 'Have to convert to String Array since that is what Lines is
Next
End Sub