求教VB读取txt的问题
本帖最后由 qiuwei10612062 于 2013-09-05 16:36:31 编辑 1
2, 0.00012, 179.59556
4, 23.16322, 203.16266
3, 88.41360, 268.41327
2
2, 0.00017, 179.59557
4, 23.16320, 203.16274
3, 88.41379, 268.41341
3
2, 0.00013, 179.59561
4, 23.16317, 203.16268
3, 88.41366, 268.41352
4
2, 0.00015, 179.59549
4, 23.16320, 203.16273
3, 88.41370, 268.41345
5
2, 0.00020, 179.59555
4, 23.16314, 203.16268
3, 88.41359, 268.41328
我现在有以上数据在txt中,怎么用VB编程实现读取诸如
2, 0.00012, 179.59556
4, 23.16322, 203.16266
3, 88.41360, 268.41327 这样的数据,将2 0.00012 179.59556这三列的数据分别保存到3个数组中,而作为分隔用的1 2 3 4 5这一行舍去不要?(这种分隔行要不要无所谓,要的话就放到另一个数组中,跳过也可以)
我自己用逗号作为分隔符的时候1 2 3 4 5这种分隔用的空行还是会读出来,但是那一行明明没有逗号啊
[解决办法]
Dim FN As Integer, FileName As String, I As Long
Dim Str As String, Arr() As String, Data() As String
FileName = "c:\a.txt"
FN = FreeFile
Open FileName For Input As #FN
I = 0
Do Until EOF(FN)
Line Input #FN, Str
Arr = Split(Str, ",")
If UBound(Arr) > 0 Then
''''把数据存到Data数组去
ReDim Data(I * 3 + 2)
Data(I) = Arr(1)
Data(I + 1) = Arr(2)
Data(I + 2) = Arr(3)
I = I + 1
End If
Loop
Close #FN