| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 592 人关注过本帖
标题:VB里怎么把TXT文件内容提取后需要的后重新输出成文件?
只看楼主 加入收藏
xiao986211
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2015-5-9
结帖率:0
收藏
已结贴  问题点数:20 回复次数:2 
VB里怎么把TXT文件内容提取后需要的后重新输出成文件?
如把下面的数据提取
W
Z 50.52
Z-14.
Z-14.5
Z-15.
Z50.52
T3.7
UD12_R-R0.08-0.00*12.0*0.08*120.00
W
Z 50.52
Z-8.753
Z-9.053
Z-9.352
Z-9.651
Z-9.95
Z50.52
T4.9
UD6_R-R0.08-0.00*6.0*0.08*120.00
W
Z 50.52
Z-4.955
Z-5.005
Z-5.051
Z-5.097
Z-5.143
Z-5.189
Z50.52
T5.5
UD4_R0.2-R0.08-0.00*4.0*0.20*120.00
W
Z 50.52
Z-14.5
Z-15.
Z-14.5
Z50.52
T7.4
UD12_F-R0.08-0.00*12.0*0.50*120.00
W
Z 50.52
Z-10.035
Z-9.535
Z-10.035
Z-9.535
Z-10.035
Z-9.535
Z50.52
T7.7
UR1.5_T-0.00*3.0*1.50*65.00

需要成下面的内容,z 在每段落只需要最小的值,
Z-15.
T3.7
UD12_R-R0.08-0.00*12.0*0.08*120.00
Z-9.95
T4.9
UD6_R-R0.08-0.00*6.0*0.08*120.00
Z-5.189
T5.5
UD4_R0.2-R0.08-0.00*4.0*0.20*120.00
Z-14.5
T7.4
UD12_F-R0.08-0.00*12.0*0.50*120.00
Z-9.535
T7.7
UR1.5_T-0.00*3.0*1.50*65.00
2015-05-09 21:58
xiao986211
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2015-5-9
收藏
得分:0 
我的思路是先把文件按 W 分成每段再存几个文件,然后在提取整理。但是每次提取的都是一样的,
帮我看看那有问题呀。。。。。
 

Dim bit7 As String '将文本全部读入
Dim str7() As String  '分割行    分割符为“回车键”
Dim cz
Dim cc
Dim bit11 As String '将文本全部读入
Dim str11() As String  '分割行    分割符为“回车键”
Dim bit12 As String '将文本全部读入
Dim str12() As String  '分割行    分割符为“回车键”
Dim str98(100, 10000) As String
Dim v As Integer
Dim vv As Integer
Dim p As Integer

'开始读文本
Open "D:\XXX.ini" For Binary As #7
        bit7 = Space(LOF(7))
       Get #7, , bit7
       Close #7
   Open "D:\X1.ini" For Output As #10
       cz = "W" '要查找的内容
       str7 = Split(bit7, vbCrLf)
      For c = 0 To UBound(str7)
        If str7(c) = cz Then cc = c + 1: Print #10, cc
      Next
        Close #10

  Open "D:\X1.ini" For Binary As #11
        bit11 = Space(LOF(11))
       Get #11, , bit11
       Close #11
     str11 = Split(bit11, vbCrLf)
           For p = 0 To UBound(str11)
            Next
  
   Dim jj As Integer
   Dim kk As Integer
           jj = 1
           kk = 0         
      For ll = 0 To p - 2
        Open "D:\" & ll & ".ini" For Output As #11
           For w = str11(kk) To str11(kk + 1) - 2
             str98(jj, w) = str7(w)
             Print #11, str98(jj, w)
           Next
         Close #11
         If w = Val(str11(kk + 1) - 2) Then jj = jj + 1: kk = kk + 1
     在这好想就有问题,w 的值大于 str11(kk + 1) - 2 了,使得 KK 和 JJ 的值不能增加
     Next

End Sub

[ 本帖最后由 xiao986211 于 2015-5-9 23:19 编辑 ]
2015-05-09 23:17
lianyicq
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:26
帖 子:737
专家分:3488
注 册:2013-1-26
收藏
得分:20 
回复 2楼 xiao986211
我重新写了一个
自己按需要修改
程序代码:
Option Explicit
Dim Check As Boolean

Private Sub Command1_Click()
Dim Check As Boolean
Dim i As Integer
Dim LineTemp As String
Dim FirstChar As String
Dim Zover As Boolean
Dim temp() As String
Dim ZMax As Single
IniList
For i = 0 To List1.ListCount - 1
  LineTemp = List1.List(i)
  FirstChar = Mid(LineTemp, 1, 1)

 
  Select Case FirstChar
    Case Is = "W"
      Check = True
      Zover = False
      ZMax = 0
    Case Is = "Z"
      temp = Split(LineTemp, "-")
      If temp(1) > ZMax Then ZMax = temp(1)
    Case Else
      If Zover = False Then
         Zover = True
         Text1.Text = Text1.Text & "Z-" & ZMax & vbCrLf & LineTemp & vbCrLf
        
         Else
         Text1.Text = Text1.Text & LineTemp & vbCrLf
         Check = False
        
       End If
   End Select
Next

 
End Sub

Sub IniList()
Dim temp As String
Open "c:\test.ini" For Input As #1
While (Not (EOF(1)))
  Line Input #1, temp
  Select Case Mid(temp, 1, 1)
    Case Is <> "Z"
      List1.AddItem temp
    Case Is = "Z"
      If Mid(temp, 2, 1) = "-" Then List1.AddItem temp
  End Select
Wend
Close #1
End Sub

 

大开眼界
2015-05-11 10:30
快速回复:VB里怎么把TXT文件内容提取后需要的后重新输出成文件?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.027015 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved