Results 1 to 2 of 2

Thread: Who can help me to read string???

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2001
    Posts
    2

    Angry Who can help me to read string???

    I have 2 questions below, please help me.
    1)I have a large UNIX log text file above 6Mb. And I must read it line by line. How can I do it by VB programming?
    (This is my codes :
    First change the file from UNIX to PC format, and read it line by line next.
    Open "12345.log" For Input As 1
    Open "12345.tmp" For Output As 2
    While Not EOF(1)
    Line Input #1, sBuffer '(VB tell me No Memory on this step!!!!!!)
    sBuffer = Replace(sBuffer, Chr(10), vbCrLf)
    Print #2, sBuffer
    Wend
    Close #2
    Close #1

    Open "12345.tmp" For Input As 1
    Line Input #1, sBuffer
    ........
    Do you have any good method to read UNIX log file line by line?

    2)I need read something from the string like:
    "aaa<SPACE or TAB>bbb<SPACE or TAB>ccc<SPACE or TAB>ddd<SPACE or TAB>...."
    The string is splited by TAB or SPACE, and I need read the sub string between SPACE or TAB. For example, read the sub string between No.22 SPACE and No.23 SPACE or No.20 TAB and No.21 TAB; Or between No.21 TAB and No.22 SPACE.
    How can I do it by VB programming?

    Thanks for your help!!

    Best Regards.

  2. #2
    Fanatic Member Kaverin's Avatar
    Join Date
    Oct 2000
    Posts
    930
    I believe the "out of memory" error is a result of how the file is delimited. I know nothing of UNIX, but from what you say, it seems that new lines are separated only by a linefeed, Chr$(10), character. Line Input treats a line as everything up to a vbCrLf, which is a Chr$(13) & Chr$(10) combo. If that's true, that Line Input statement is attempting to read the whole file, as it will probably never encounter the 13 10 combo in that order. This will do your conversion.
    VB Code:
    1. Dim i As Long
    2. Dim b As Byte
    3. Open "c:\unix.log" For Binary As #1
    4. Open "c:\converted.log" For Binary As #2
    5. For i = 1 To LOF(1)
    6.    'read a byte
    7.    Get #1, , b
    8.    'if it was a linefeed, stick in a carriage return next
    9.    If Chr$(b) = vbLf Then Put #2, , vbCr
    10.    'now write the byte.  any 10 has been converted to the proper 13 10 combo
    11.    Put #2, , b
    12. Next i
    13. Close #2
    14. Close #1
    For your second question, you can use the function Split() to break up the string at a specified character like space or tab, or even a group of characters.
    VB Code:
    1. Dim astrPieces() As String
    2. astrPieces = Split("this is my string"," ")
    3. 'astrPieces(0) = "this"
    4. 'astrPieces(1) = "is" and so on
    I'm baaaack...
    VB5 Professional Edition, VC++ 6
    Using a 1 gHz Thunderbird, 256 mb RAM, 40 gb HD system with Win98se

    I feel special because I finally figured out how to loop midis: Post link
    I'm a fanatic too

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