Complex text file import problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SDEBEUL
    New Member
    • Jun 2013
    • 1

    Complex text file import problem

    Hi,
    I have a complex text file import issue.

    The first 13 lines of the file need to be skipped.

    Then each of the next 2 lines need to be combined in one record.
    the format of one record should look something like this ..
    index number / date / time / error code / error description

    Help would be greatly appreciated.

    g's Sam

    Code:
    ****************************************
    *                                      *
    *  C O M A U  :  Robotics              *
    *                                      *
    d*  C 3 G  :  3^ Generation Control     *
    *                                      *
    *       ERROR      LOG      FILE       *
    *                                      *
    ****************************************
    * ERROR FORMAT RELEASE     : 1.0       *
    * MAX REMEMBERED ERRORS    :  20       *
    * LATEST ERROR IN POSITION :   5       *
    * ERROR LINE LENGTH        :  80       *
    ****************************************
    
    
    
    <001>    08-11-12 09:15:15
    30777-10 : DP SL slave not ready                                                
    <002>    08-11-12 09:26:00
    43276-04 : A_SW1B: $DIN[2]=OFF, micro not indicates "gun open"                  
    <003>    08-11-12 09:27:42
    36912-04 : rsssssrr(34): unmatching FOR loop                                    
    <004>    08-11-12 09:55:29
    62479-08 : SA: 1 1 wrist axis at undefined position                             
    <005>    08-11-12 10:09:29
    62482-10 : SAX: 1 1 1 tolerance HOLD unobtainable                               
    <006>    08-11-12 06:17:39
    28774-10 : Power failure detected                                               
    <007>    08-11-12 06:17:40
    43274-04 : A_SW1B: MP 1 $DIN[35]=OFF, no air                                    
    <008>    08-11-12 06:17:49
    30777-10 : DP SL slave not ready                                                
    <009>    08-11-12 06:19:47
    43260-10 : Welding control switch 1 failure                                     
    <010>    08-11-12 06:25:07
    43522-04 : HTChg: Tool on flange INP fault $DIN[ 16] = ON                       
    <011>    08-11-12 06:25:16
    43522-04 : HTChg: Tool on flange INP fault $DIN[ 16] = ON                       
    <012>    08-11-12 06:25:27
    43522-04 : HTChg: Tool on flange INP fault $DIN[ 16] = ON                       
    <013>    08-11-12 06:27:13
    30777-10 : DP SL slave not ready                                                
    <014>    08-11-12 06:38:32
    61442-11 : SAX: 1 1 2 following error out of range                              
    <015>    08-11-12 06:41:21
    43274-04 : A_SW1B: MP 1 $DIN[35]=OFF, no air                                    
    <016>    08-11-12 06:41:21
    43292-04 : A_SW1B: [02] Switch  1 $GIN[14] = 0. Welding control switch not open 
    <017>    08-11-12 06:46:26
    28774-10 : Power failure detected                                               
    <018>    08-11-12 06:46:26
    26636-10 : BS: (0,5) I/O module failed                                          
    <019>    08-11-12 06:46:36
    30777-10 : DP SL slave not ready                                                
    <020>    08-11-12 06:46:55
    43260-10 : Welding control switch 1 failure
    Last edited by Rabbit; Jun 24 '13, 05:08 PM. Reason: Please use code tags when posting code or formatted data.
  • zmbd
    Recognized Expert Moderator Expert
    • Mar 2012
    • 5501

    #2
    SDEBEUL
    What have you tried so far?

    We can help you with a specific snag in your code; however, we need something to work with first.

    Also, the record you propose doesn't seem to follow the normalization rules: Database Normalization and Table Structures.
    Last edited by zmbd; Jun 24 '13, 11:16 PM.

    Comment

    • ADezii
      Recognized Expert Expert
      • Apr 2006
      • 8834

      #3
      Here is the Logic as I see it:
      1. Input each Line of the File into a Variable.
      2. Ignore the first 13 Lines of the File.
      3. Analyze each Line. If it is an Index Line, just remember it, but if it is not, build a String consisting of the Index Line, a Separator (|), and the next consecutive Line after the Index Line.
      4. Output each Line to an Output File.
      5. Loop through the entire File until the end is reached, using the same Logic for each Line.
        Code:
        Dim intLineNum As Integer
        Dim strIndex As String
        Dim strBuild As String
        
        Open "C:\Test\Input.txt" For Input As #1    'Input File
        Open "C:\Test\Output.txt" For Output As #2  'Output File
        
        intLineNum = 0                              'Initialize
        
        Do While Not EOF(1)                         'Loop until end of file.
          intLineNum = intLineNum + 1               'Increment Line Number
            Line Input #1, strLine                  'Input entire Line into a Variable
              If intLineNum > 13 Then               'Skip the first thirteen Lines
                If Left$(strLine, 1) = "<" Then     'Is it an Index Line, yes if '<'?
                  strIndex = strLine
                    strBuild = ""                   'Don't concatenate, Index Line
                Else
                  'Build String, (Index Line & ' | ' & Line below)
                  strBuild = strIndex & " | " & strLine
                End If
                  Print #2, strBuild
              End If
        Loop
        
        Close #1    'Close Input File
        Close #2    'Close Output File
      6. This Code does work with certain parameters, but it is only meant to be a general guildline for you to follow. Any other questions, please feel free to ask.
      7. Sample Output after executing Code, using limited Data:
        Code:
        <001>    08-11-12 09:15:15 | 30777-10 : DP SL slave not ready                                                
        <002>    08-11-12 09:26:00 | 43276-04 : A_SW1B: $DIN[2]=OFF, micro not indicates "gun open"                  
        <003>    08-11-12 09:27:42 | 36912-04 : rsssssrr(34): unmatching FOR loop                                    
        <004>    08-11-12 09:55:29 | 62479-08 : SA: 1 1 wrist axis at undefined position

      Comment

      Working...