1.txt有若干行
1234
4566
789
……
把txt中的每行导入到list1中
然后再有1个command按钮
可以把 list1的内容导入回1.txt
求帮助
VB txt文本导入list 再导出
答案:3 悬赏:10 手机版
解决时间 2021-02-12 10:31
- 提问者网友:鐵馬踏冰河
- 2021-02-11 14:33
最佳答案
- 五星知识达人网友:梦中风几里
- 2021-02-11 15:22
'保存
On Error Resume Next
Dim i As Integer
Open App.path+"\List.lst" For Output As #1
For i = 1 To Me.List1.ListCount - 1
Print #1, Me.lsList1.List(i)
Next i
Close #1
'加载
Dim MyString As String
Open App.path+"\List.lst" For Input As #1
Do While Not EOF(1)
DoEvents
Line Input #1, MyString
Me.List1.Additem MyString
Loop
Close #1
On Error Resume Next
Dim i As Integer
Open App.path+"\List.lst" For Output As #1
For i = 1 To Me.List1.ListCount - 1
Print #1, Me.lsList1.List(i)
Next i
Close #1
'加载
Dim MyString As String
Open App.path+"\List.lst" For Input As #1
Do While Not EOF(1)
DoEvents
Line Input #1, MyString
Me.List1.Additem MyString
Loop
Close #1
全部回答
- 1楼网友:人類模型
- 2021-02-11 17:19
(1)text文本每一行导入list1:
private sub inputList1()
dim SD as string
SD=text1.text
dim A() as string
A()=split(SD,VBcrlf)
dim i as integer
for i=0 to ubound(A) step 1
List1.AddItem A(i)
Next i
end sub
(2) List1内容传回
Private sub List1_click()
dim SS as string
SS=List1.List(List1.Listindex)
Text1.Text=SS
end sub
- 2楼网友:西风乍起
- 2021-02-11 16:33
Private Sub Command1_Click()'导入
List1.Clear
Dim TextLine
Open App.Path & "\1.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, TextLine
List1.AddItem (TextLine)
'A = A & TextLine
Loop
Close #1
Print A
End Sub
Private Sub Command2_Click()'导出
On Error Resume Next
Dim str As String
str = ""
For i = 0 To List1.ListCount
str = str & vbCrLf & List1.List(i)
Next i
Open App.Path & "\2.txt" For Output As #1
Print #1, Mid(str, 3, Len(str) - 4)
Close #1
End Sub
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯