来帮忙看看怎么取这个txt文件中的数据

triper 2005-04-14 11:43:01
文本文件的内容是这样的格式:

E:\容器\10.DTA
DiSP (r) Location Version
E:\容器\10.DTA
DiSP (r) Location Version

Version E1.8
AEwin for DiSP
Thu Jan 08 12:47:23 2004

ID SSSSSSSS.mmmuuun
2 0.0104193

ID SSSSSSSS.mmmuuun CH RISE COUN ENER DURATION AMP PCNTS
1 0.0141927 1 1 1 0 1 61 1
1 0.0203083 8 10 1 0 11 65 1
1 0.4857988 8 3 2 0 18 62 1
1 0.9780492 1 3 1 0 6 62 1
1 0.9859860 8 1 1 0 1 61 1

ID SSSSSSSS.mmmuuun
2 1.0100445

ID SSSSSSSS.mmmuuun CH RISE COUN ENER DURATION AMP PCNTS
1 1.0333533 6 2 2 0 15 63 1
1 1.0333800 5 1 1 0 1 61 1
1 1.0335188 1 21 4 0 169 62 1

ID SSSSSSSS.mmmuuun
2 2.0100440

ID SSSSSSSS.mmmuuun CH RISE COUN ENER DURATION AMP PCNTS
1 2.0217802 7 11 9 10 62 71 2
1 2.0351552 8 23 6 0 37 63 4

数据有很多,中间我删了一部分.主要要求是根据CH一列的数据,把相同数据的行提取出来.但文本的写入格式不明,最后我试出了那列数据的位置(大概为用空格分割后的第14个数据)

Private Sub Command1_Click()
wenjian = Text1.Txt
For i = 1 To 8 '先后搜集1到8的数据行

Open wenjian For Input As 1
Do While Not EOF(1)
Line Input #1, shujv
b = Split(shujv, " ")
a = UBound(b) '得到b的上限
If a >= 43 Then '排除没用的行
DUISHU = CDbl(b(13)) '将字符转换为数字
If DUISHU = i Then '挑出数据
duchu = duchu + shujv + vbCrLf
End If
End If
Loop
Close #1
Next
'输出整理的结果
Open wenjian + ".txt" For Output As 2
Write #2, duchu
Close #2
End Sub

但中间这个语句出毛病了:
DUISHU = CDbl(b(13)) '将字符转换为数字
因为在排除没用的行时,有些不是数据的行没有排除掉,比如这样的行:
ID SSSSSSSS.mmmuuun CH RISE COUN ENER DURATION AMP PCNTS
在字符转换为数字时就会出错,我该怎么解决啊,同志们帮个忙~~
...全文
64 点赞 收藏 4
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
homezj 2005-04-15
Private Sub Command1_Click()
Dim a() As String, s As String, i As Long
Dim b() As String, c() As String, k As Long
Dim wenjian As String
wenjian = Text1.Text
Open wenjian For Input As 1
s = Input(LOF(1), 1)
Close
s = Mid$(s, InStr(1, s, "ID SSSSSSSS.mmmuuun"))
s = Replace$(s, vbCrLf & vbCrLf, vbCrLf)
a = Split(s, vbCrLf)
a = Filter(a, "ID SSSSSSSS.mmmuuun", False)
For i = 0 To UBound(a)
s = Trim$(a(i))
s = Replace$(s, " ", "| |")
b = Split(s, " ")
b = Filter(b, "||", False)
If UBound(b) > 1 Then
b(2) = Replace$(b(2), "|", "")
If IsNumeric(b(2)) Then
If b(2) >= 1 And b(2) <= 8 Then
ReDim Preserve c(k)
c(k) = a(i)
k = k + 1
End If
End If
End If
Next
'输出整理的结果
Open wenjian + ".txt" For Output As 1
Print #1, Join(c, vbCrLf)
Close #1
End Sub
回复
triper 2005-04-15
果然强啊,高手就是高手~~~
不过这一部分不能用:
Dim wenjian As String
wenjian = Text1.Text
Open wenjian For Input As 1
s = Input(LOF(1), 1)
Close
要改成:
Dim wenjian As String
wenjian = Text1.Text
Open wenjian For Binary As 1
s = Space(LOF(1))
Get 1, , s
Close
否则会出错
回复
myhgyp 2005-04-15
先留个记号
回复
小吉,偶像哦
回复
相关推荐
发帖
VB基础类
创建于2007-09-28

7489

社区成员

VB 基础类
申请成为版主
帖子事件
创建了帖子
2005-04-14 11:43
社区公告
暂无公告