Private Sub Form_Load() Dim i As Integer, s1 As String If Dir(App.Path & "\1.txt") <> "" Then Open App.Path & "\1.txt" For Input As #1 For i = 0 To List1.ListCount - 1 Line Input #1, s1 List1.AddItem s1 Next i Close #1 End If End Sub Private Sub Form_Click() Dim i As Integer Open App.Path & "\1.txt" For Output As #1 For i = 0 To List1.ListCount - 1 Print #1, List1.List(i) Next i Close #1End Sub
你可以把一项listbox写成一行,读的时候读一行,就加载一行
Dim i As Integer, s1 As String
If Dir(App.Path & "\1.txt") <> "" Then
Open App.Path & "\1.txt" For Input As #1
For i = 0 To List1.ListCount - 1
Line Input #1, s1
List1.AddItem s1
Next i
Close #1
End If
End Sub
Private Sub Form_Click()
Dim i As Integer
Open App.Path & "\1.txt" For Output As #1
For i = 0 To List1.ListCount - 1
Print #1, List1.List(i)
Next i
Close #1End Sub