标题:读取多个文件按行读取一个文件一行怎么不行能呢?
取消只看楼主
VBnext
Rank: 1
等 级:新手上路
帖 子:33
专家分:0
注 册:2013-4-24
结帖率:80%
已结贴  问题点数:20 回复次数:2 
读取多个文件按行读取一个文件一行怎么不行能呢?
读取.log文件,为什么程序执行到       Line Input #1, strtemp
strTemp读取的字符串内容要比用UltraEdit工具打开的.log文件一行要多很多内容?如用UltraEdit工具打开的.log第一行内容<IOEXP;
而程序读取缺内容很多。请问这是什么问题呢?
程序如下:

Private Sub cddd_Click()
Dim a() As String
Dim filemanyaddress, files, strfilename, i, fn
Dim strtemp As String
    With CommonDialog1
        .DialogTitle = "打开"
        .CancelError = False
        .Filter = "all log (*.log)|*.*"
        .Flags = cdlOFNAllowMultiselect Or cdlOFNExplorer
        .ShowOpen
        If Len(.FileName) = 0 Then
          Exit Sub
        End If
          filemanyaddress = .FileName
    End With
   
    files = Split(filemanyaddress, Chr(0))
    ReDim a(UBound(files))
        For i = 1 To UBound(files)
        a(i) = files(0) & "\" & files(i)
        Next i
''---------------------------------------------------------------------------------------------------------
 For fn = 1 To UBound(a)
     Dim s As String
     Open a(fn) For Binary As #1
     Do While Not EOF(1)
       Line Input #1, strtemp(出现问题)
       MsgBox strtemp
         Select Case strtemp
                    Case "<RLCFP:CELL=ALL;"
                       Call RLCFP
                    Case "<RLDEP:CELL=ALL;"
                        Call RLDEP
                    Case "<RLNRP:CELL=ALL;"
                        Call RLNRP
            End Select
     Loop
     Close #1
 Next fn
End Sub
请大手子帮忙看看?读取文件如下:
CDDlog.rar (579.75 KB)
搜索更多相关主题的帖子: 字符串 files False 
2013-07-10 17:42
VBnext
Rank: 1
等 级:新手上路
帖 子:33
专家分:0
注 册:2013-4-24
得分:0 
没人能回答吗??????
2013-07-12 10:55
VBnext
Rank: 1
等 级:新手上路
帖 子:33
专家分:0
注 册:2013-4-24
得分:0 
回复 2楼 风吹过b
您好!我利用FileSystemObject可以直接读取该.log文件安行读取
可是我遇到问题是:
我想把.log文件的内容:
<RLCFP:CELL=ALL;
CELL CONFIGURATION FREQUENCY DATA

CELL
D088041

CHGR   SCTYPE    SDCCH   SDCCHAC   TN   CBCH     HSN   HOP  DCHNO
 0                3       0        1    NO       56    ON    512
                                   3                         551
                                   5                         557
                                   7
 1                0       0        2    NO       16    OFF   548
整理为如下:
 BSC       CELL    CHGR    SCTYPE    SDCCH    SDCCHAC    TN       CBCH    HSN    HOP    DCHNO
TABS33    D088041    0                 3        0     1 3 5 7     NO     56      ON     512 551 557
TABS33    D088041    1                 0        0      2          NO     16      OFF    548
当读到第一行:( 0                3       0        1    NO       56    ON    512
)是长度和第二行的字符串的长度不一致,而且只能用空格把该行字符串拆分

程序如下:
Private Sub cddd_Click()
Dim a() As String
Dim filemanyaddress, files, strfilename, i, j, fn, ln
Dim strtemp As String, MyStr As String, MyCell As String, xChar As String

Dim frArray() As String, temp(5) As String
Dim fso As Object
Dim inputFile As Object

    With CommonDialog1
        .DialogTitle = "打开"
        .CancelError = False
        .Filter = "all log (*.log)|*.*"
        .Flags = cdlOFNAllowMultiselect Or cdlOFNExplorer
        .ShowOpen
        If Len(.FileName) = 0 Then
          Exit Sub
        End If
          filemanyaddress = .FileName
    End With
   
    files = Split(filemanyaddress, Chr(0))
    ReDim a(UBound(files))
        For i = 1 To UBound(files)
        a(i) = files(0) & "\" & files(i)
        Next i
'    --------------------------------------------------------------------------------------------------------
 For fn = 1 To UBound(a)
 
     Set fso = CreateObject("Scripting.FileSystemObject")
     Set inputFile = fso.OpenTextFile(a(fn))
     Do While Not inputFile.atEndOfStream
       MyStr = inputFile.readLine()
  
        Select Case MyStr

'    --------------------------------------------------------------------------------------------------------
            Case "<RLCFP:CELL=ALL;"
              Do While Not inputFile.atEndOfStream
               
                MyStr = inputFile.readLine()
                 MsgBox (MyStr)
                    
                    If MyStr = "END" Then Exit Sub
                    If MyStr = "CELL" Then temp(0) = inputFile.readLine()
                    If MyStr = "CHGR   SCTYPE    SDCCH   SDCCHAC   TN   CBCH     HSN   HOP  DCHNO" Then
                        
                          Do While Not inputFile.atEndOfStream
                                MyStr = inputFile.readLine()
                                If Len(MyStr) = 0 Then Exit Do

                                If MyStr = "END" Or MyStr = "FAULT INTERRUPT" Then Exit Sub

                                  For j = 1 To Len(MyStr)
                                    xChar = Mid(MyStr, j, 1)
                                    If Asc(xChar) <> 10 Then
                                      MyCell = MyCell & vbCrLf & xChar
                                    End If
                                    
                                  Next
                                MsgBox (MyCell)
                               frArray = Split(MyCell, vbCrLf)
                          Loop
                    End If

               Loop
            Case "<RLNRP:CELL=ALL"
            
            Case "<RLDEP:CELL=ALL"
         End Select
     Loop
   
 Next fn
End Sub
请帮帮看看,该怎样解决?
2013-07-12 11:29



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-417064-1-1.html




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

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