vb如何读取文本文件中指定内容

如mytext.txt文本中有如下内容:
sam1 lhd
sam2 lys
sam3 xg
sam4 zxw
......
我需要读取sam1,sam2,sam3.....到a.txt中或用Text控件显示
我是新手,望能给源代码指点,这里谢谢了

ttt=""
Open App.Path & "\mytext.txt" For Input As #1 '打开源文本
Do While Not EOF(1)
Line Input #1, aa '读入一行
a = Split(aa, " ")'按空格进行分列,填入数组a中
ttt=a(0) & VBCRLF'把A的第一个项目拿出来,就是sqm1...添加到ttt文本变量中
Loop
Close #1
Text1.Text = ttt '把ttt的内容给予text1
MsgBox "完成"
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2016-10-07
  代码:
Private Sub Command_Click()
Dim a As String

Open "C:\\mytext.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, a
Text1.Text=Text & a & vbCrLf
Loop
Close #1
相似回答