VB怎麼把列表框内容自动存取为TXT文档,又如何把TXT内容导入到列表框

来源:百度知道 编辑:UC知道 时间:2024/06/17 15:48:22

Option Explicit

Private Sub Command1_Click()
'保存列表框内容
Dim i As Integer
Open "d:\list1.txt" For Output As #1 '自己设置保存路径
For i = 0 To List1.ListCount - 1
Print #1, List1.List(i)
Next
Close #1
End Sub

Private Sub Command2_Click()
'打开文件到列表框
Dim strLine As String
Open "d:\list1.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, strLine '按行添加
List1.AddItem strLine
Loop
close
End Sub