vb 逐行读取TXT文件内容 譬如每一行类型都是XXXABC,并导入到LIST1中(不能重复)

还有如何逐行运行list1中内容

Private Sub Command1_Click()
Dim str, i, j
List1.Clear
Open "test.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, str
str = UCase(Trim(str))
For i = 0 To List1.ListCount - 1
If List1.List(i) = str Then Exit For
Next
If str <> "" And j = List1.ListCount Then List1.AddItem str
Loop
Close #1
End Sub追问

如何逐行运行LIST中内容,譬如LIST第一行为ABC123(每一行都没有规律),过5秒,此过程为一次;再运行一个list中下一行,譬如DEF456.........以此类推,到10000次结束。
最好有注释。看的清楚

追答

什么叫逐行运行LIST中内容,能解释的详细点吗?
是不是将LIST的内容每隔5秒显示到文本框中?

追问

是的 将LIST的内容每隔5秒显示到文本框中

追答

'须在在窗体上放置Command1控件、Text1控件和Timer1控件
Dim step As Integer
Private Sub Command1_Click()
Dim str As String, i As Integer, j As Integer
List1.Clear
Open "test.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, str
str = UCase(Trim(str))
For i = 0 To List1.ListCount - 1
DoEvents
If List1.List(i) = str Then Exit For
Next
If str "" And j = List1.ListCount Then List1.AddItem str
Loop
Close #1
Timer1.Enabled '启动定时器’
End Sub

Private Sub Form_Load()
Text1.Text = "" '初始化text1控件
step = 0 '初始化list1控件指向第0行
Timer1.Interval = 5000 '设置定时器计时间隔为5秒
Timer1.Enabled = False '关闭定时器
End Sub

Private Sub Timer1_Timer()
If step < List1.ListCount Then
Text1.Text = Text1.Text & List1.List(step) & vbCrLf
step = step + 1
Else
Timer1.Enabled = False
End If
End Sub

温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-04-23
在窗体上创建一个按钮command1 一个文本框text1 一个列表控件 List1

private sub command1_click()
Dim strDataBuff As String

text1.text=""
Open "txtfile.txt" For Input As #1
Do Until Eof(1)
Line Input #1,strDataBuff
'if instr(text1.text,strDataBuff)>0 then
'else
List1.AddItem strDataBuff
' text1.text=text1.text & "," & strDataBuff
'end if
Do Events
End Do
Close #1
end sub

如果你不希望在List1表中添加重复的数据的话,只要把注释掉的代码 启用就行了
相似回答
大家正在搜