Results 1 to 3 of 3

Thread: Input a LONG continuous record file

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2000
    Location
    Texas
    Posts
    17
    Have a file that is one long continuous record (no CRLF) and may have 1 to 10,000+ strings of 333 characters each (it is a type of error DUMP file). I need to create a file that reads this DUMP file in & writes out certain sections of each string group. I have a code segment that works if the DUMP file is very small, but because it inputs the dump file as a string, it hits OVERFLOW if the file has any size to it at all. (the program also displays to a text box)
    Here is the code segment>

    Open "c:\dumpfile" for Input As #1
    Input #1, strfiledata
    iLength = Len(strfiledata)
    iSectionCount = iLength / 333
    iStartPosition = 1
    Close #1
    Open "c:\TCDataOut.txt" For Output As #2

    For iLoopVar = 1 To iSectionCount
    Text1.Text = Text1.Text & vbCrLf & Mid$(strfiledata, iStartPosition + 11, 15) & " " & Mid$(strfiledata, iStartPosition + 29, 12) & " " & Mid$(strfiledata, iStartPosition + 190, 12)
    iStartPosition = iStartPosition + 333
    Next iLoopVar
    Print #2, Text1.Text

    Hope this makes some sense. I'll bet there is a MUCH easier way to do this.

    Thanks 4 helping (& for reading all the way to the bottom)

    thanks, jackie

  2. #2
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Auckland, NZ
    Posts
    411

    Several Problems

    I have posted an alternative that is untested but looks ok.

    FYI:
    In my example there are still some issues I can imagine will hit you.

    1) Text boxes are up to 32000 characters I think so this limit will affect you. Consider moving to a rich text box which I don't think has a limit (?)

    2) You were trying to load in a huge string which is unnecessary. If you want to process each "record" then you might as well do that as you read them. Takes less memory so is faster. Note that is you truly did want to read all the data inot one string or perhaps an array, This is quite easy using an API call to CopyMemory and a byte array - but that's another topic.

    3) Your code was outputting the contents of text1.text to the output file each time you parsed a new record. This means that the output file would grow quite big as you output 1 record, then 2, then 3 etc. So after 10 records, you would have had 10+9+8+7+6+5+4+3+2+1 records dumped instead of 10 which is what I think you want.

    4) As a rule, don't use controls as variable storage space - declare a variable instead. By setting the text1.text property, then reading it, you are relying on the text box to maintain the integrity of the data. Don't rely on it because text box will alter the text if it wants to. The same goes with any control at all.

    So with no further ado, try this code.

    Code:
    ' decalration of our custom type
    Option Explicit
    Public Type dumpRecord
      text As String * 333
    End Type
    Code:
      Dim c As Integer
      Dim tmp As dumpRecord
      Dim outText As String
      
      Open "c:\dumpfile" For Random As #1
      Open "c:\TCDataOut.txt" For Output As #2
      
      While Not EOF(1)
        Input #1, tmp
        c = c + 1
        outText = Mid$(tmp, 11, 15) & " " & Mid$(strfiledata, iStartPosition + 29, 12) & " " & Mid$(tmp, 190, 12)
        Text1.text = Text1.text & outText
        Print #2, outText
      Wend
      
      Close #1
      Close #2

    Regards
    Paul Lewis

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Aug 2000
    Location
    Texas
    Posts
    17
    Thanks Paul. That worked for me. Your notes also
    solved issues that I had set aside to work out
    later.
    thanks, jackie

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width