VB中,在txt文档中提取指定一行数据

Cyc PPStrain PVStress E
1 4.70333919168425E-03 -84.7727604695744 19581.83
2 4.8110062269861E-03 -94.052230798543 20612.79
3 4.73714240787696E-03 -101.308596418401 20707.83
4 4.86445472249531E-03 -96.1913166385123 20111.8
5 4.92190035491681E-03 -96.2646482048903 19572.96
6 4.95765081108269E-03 -97.027030809558 19796.16
例如将Cyc/2这一行的数据取出再存在另一个txt文档中,求大神指点!

Private Sub Command1_Click()
Dim n As Integer, s As String, k As Boolean
n = Val(InputBox("请输入想要保存的序号:"))
Open "c:\1.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, s
If Trim(Left(s, 5)) = n Then
Open "c:\2.txt" For Output As #2
Print #2, s
k = True
Exit Do
End If
Loop
Close #1
Close #2
If Not k Then MsgBox "未找到序号为" & n & "的行!" Else MsgBox "成功保存序号为" & n & "的行!"
End Sub

温馨提示:答案为网友推荐,仅供参考
相似回答