用VB做了个小程序,怎么才能使程序关闭后,再次打开,列表框的数据还是存在呢?我是新手,越简单越好!

或者关闭后自动保存到TXT或 execel中也行。
2024-11-02 12:28:46
推荐回答(3个)
回答1:

Private Sub Form_Load()'启动时加载
If Dir(App.Path & "\date.txt") <> "" Then
f% = FreeFile
Open App.Path & "\date.txt" For Input As f
Do Until EOF(f)
Line Input #f, s
List1.AddItem s
Loop
close #f
End If
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
f% = FreeFile'退出时保存
Open App.Path & "\date.txt" For Output As f
For i = 0 To List1.ListCount - 1
Print #f, List1.List(i)
Next
close #f
End Sub

回答2:

用open...for...as...语句保存到文件

回答3:

程序里在formload里写死不就行了吗?