如何用VB读取循环数据文件,每组有八行,每行数据不一样
1 01 2 20 23 59 44.0 .165715813637D-03 .147792889038D-11 .000000000000D+00
.183000000000D+03 -.118062500000D+03 .422089010273D-08 -.282023116721D+01
-.617280602455D-05 .519775517751D-02 .656768679619D-05 .515361128998D+04
.259184000000D+06 .000000000000D+00 -.817046568858D+00 -.372529029846D-07 8行
.963449106517D+00 .253875000000D+03 -.172063150956D+01 -.786747056887D-08
-.316084594764D-09 .000000000000D+00 .110200000000D+04 .000000000000D+00
.200000000000D+01 .000000000000D+00 -.325962901115D-08 .183000000000D+03
.259199000000D+06
1 01 2 20 23 59 44.0 .165715813637D-03 .147792889038D-11 .000000000000D+00
.183000000000D+03 -.118062500000D+03 .422089010273D-08 -.282023116720D+01
-.617280602455D-05 .519775517751D-02 .656768679619D-05 .515361128998D+04 8行
.259184000000D+06 .000000000000D+00 -.817046568858D+00 -.372529029846D-07
.963449106517D+00 .253875000000D+03 -.172063150956D+01 -.786747056887D-08
-.316084594764D-09 .000000000000D+00 .110200000000D+04 .000000000000D+00
.200000000000D+01 .000000000000D+00 -.325962901115D-08 .183000000000D+03
.259199000000D+06
第一行分别是点名,年,月,日,时,分,秒,然后是三个double数据,每行都是80列。第二行分别是四个double数据,以此类推,这些数据读出来要分配到不同的变量中。像这样的8行有若干行。 请教:已用line input 读取第一行, 如何自动转到能读取第二行??谢谢
我附上我的代码,请指正
For count = 1 To 7
Line Input #Filenum, bbb
bbb = Trim$(bbb)
NSK = Trim$(Mid$(bbb, 1, 2)) '编号
Nnum = Val(NSK)
NSK = Trim$(Mid$(bbb, 3, 3))
Nyear = Val(NSK)
NSK = Trim$(Mid$(bbb, 6, 3))
Nmonth = Val(NSK) ‘月份
NSK = Trim$(Mid$(bbb, 9, 3))
Nday = Val(NSK) ‘日
NSK = Trim$(Mid$(bbb, 12, 3))
Nhour = Val(NSK) ‘时
NSK = Trim$(Mid$(bbb, 15, 3))
Nmintue = Val(NSK) ‘分
NSK = Trim$(Mid$(bbb, 18, 2))
Nsecond = Val(NSK) ‘秒
NSK = Val(Mid$(bbb, 23, 18))
Nclcd = CDec(NSK)
NSK = Val(Mid$(bbb, 42, 18))
Nclcevc = CDec(NSK)
NSK = Val(Mid$(bbb, 61, 18)) ‘第一行数据读完
Nclcrat = CDec(NSK)
bbb = Trim$(bbb) ‘第二行第一个数据读不出来了
NSK = Val(Mid$(bbb, 1, 16))
NIODE = CDec(NSK)
Next
Close #Filenum '关闭打开的文件
[解决办法]
加循环
Dim TextLine
Open "TESTFILE" For Input As #1 ' 打开文件。
Do While Not EOF(1) ' 循环至文件尾。
Line Input #1, TextLine ' 读入一行数据并将其赋予某变量。
Debug.Print TextLine ' 在调试窗口中显示数据。
Loop ' 循环结束
[解决办法]
整儿儿读到字符串里, 先用回车split成行, 每行再用空格split成字段内容