我正在尝试编写一个从访问文件中获取数据的程序,然后我可以点击一个按钮并在文本文件中为其创建一个标签。现在,如果我点击按钮为多个标签创建标签,它只会显示最后一个被选中的标签。我想,我需要一个循环outfile.write's
,我只是不确定要使用什么循环。它没有给我任何错误或任何东西,它只是没有在这个文本文件中打印一个以上的标签。另外,我如何在例如人名和姓氏之间放置空格,因为它们在同一行?到目前为止,这是我的代码。
Imports System.IO
Public Class frmAccess
Dim outFile As StreamWriter
Private Sub TblMemberBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TblMemberBindingNavigatorSaveItem.Click
Me.Validate()
Me.TblMemberBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.GolfDataSet)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'GolfDataSet.tblMember' table. You can move, or remove it, as needed.
Me.TblMemberTableAdapter.Fill(Me.GolfDataSet.tblMember)
End Sub
Private Sub cmdCreate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCreate.Click
Dim outFile As StreamWriter
outFile = File.CreateText("Labels.txt")
outFile.WriteLine()
outFile.WriteLine()
outFile.Write(lblFirst.Text, " ")
outFile.WriteLine(lblLast.Text)
outFile.WriteLine(lblAddress.Text, " ")
outFile.Write(lblCity.Text, ", ")
outFile.Write(lblState.Text, " ")
outFile.Write(lblZip.Text)
outFile.WriteLine()
outFile.Close()
End Sub
Private Sub cmdExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExit.Click
Me.Close()
End Sub
End Class
例如,我的文本文件应如下所示(xxx= 空行):
xxxx
xxxxx
鲍勃·史密斯
123修复路
佛罗里达州坦帕市 12345
xxxxxx
xxxxxx
xxxxxx
简·多伊
987帮助巷
科罗拉多州丹佛 56789
xxxxx
xxxxx
因此,我的文本文件不会显示两个标签,而只会显示 Jane Doe 的标签。