我的项目中有一个保存按钮,它应该将我的 2 个列表框的内容保存到一个文本文件中,但它并没有保存所有内容。相反,它会删除其中一个列表框的最后 5 行。我的代码做错了什么?
Dim loops As Integer 'Declare variable
Dim savefile As New SaveFileDialog
savefile.FileName = ""
savefile.Filter = "textfiles(*.txt)|*.txt|file(*)|*|All files('.')|'.')"
savefile.Title = "save"
savefile.ShowDialog()
Try
Dim write As New System.IO.StreamWriter(savefile.FileName) 'Write and save a new file
For loops = 1 To itemcount - 1 'loop until no lines are left in listbox
write.WriteLine(firstname(loops)) 'Write out firstname
write.WriteLine(lastname(loops)) 'Write out lastname
write.WriteLine(gender(loops)) 'Write out gender
write.WriteLine(applicationdate(loops)) 'Write out date of regestration
write.WriteLine(address(loops)) 'Write out address
Next
write.Close() 'Close file
MsgBox("File Saved") 'Display message box
Catch ex As Exception
End Try