急求这个问题谁会

fly_918 2008-03-03 02:16:58
急求~~~~~~~把list的内容写入txt后怎么再从txt中读出?????
Dim a As Integer
Open App.Path & "\文档.txt" For Output As #1
For a = 0 To List1.ListCount - 1
Print #1, List1.List(a)
Next a
Close #1

...全文
76 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
of123 2008-03-03
  • 打赏
  • 举报
回复
Dim a As Integer, strTmp As String
Open App.Path & "\文档.txt" For Input As #1
List1.Clear
Do Until EOF(1)
Line Input #1, strTmp
List1.AddItem strTmp
Loop
Close #1
If List1.ListCount Then List1.ListIndex = 0
cbm6666 2008-03-03
  • 打赏
  • 举报
回复
'添加List1 Command1 Command2

Option Explicit
Dim i%, appdisk$, aa$, fname$

Private Sub Form_Load()
appdisk = IIf(Right(App.Path, 1) = "\", App.Path, App.Path & "\")
List1.AddItem "1111"
List1.AddItem "2222"
List1.AddItem "3333"
List1.AddItem "4444"
List1.AddItem "5555"
fname = appdisk & "文档.txt"
Command1.Caption = "写入"
Command2.Caption = "读取"
End Sub

Private Sub Command1_Click() '写入
Open fname For Output As #1
For i = 0 To List1.ListCount - 1
Print #1, List1.List(i)
Next i
Close #1
MsgBox "写入完成"
End Sub

Private Sub Command2_Click() '读出
If Dir(fname) <> "" Then
List1.Clear
Open fname For Input As #1
While Not EOF(1)
Line Input #1, aa
List1.AddItem aa
Wend
Close #1
MsgBox "读取完成"
End If
End Sub



1,453

社区成员

发帖
与我相关
我的任务
社区描述
VB 控件
社区管理员
  • 控件
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧