Results 1 to 5 of 5

Thread: conversion

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    Calgary Alberta
    Posts
    359

    Post

    I need to read a linux text file in VB. THe problem is that Linux ends a line with hex(0A) and dos reads an end of line as hex(0A 0D). Is the any way in vb that I can switch this character. If I don't, it will read the entire file as 1 line. Since I have to seperate the lines this doesn't help me. I use perl right now but I'd like to have it all in one program.

    As an option, is there a way I can run Perl in VB?

  2. #2
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845

    Post

    this should read the file into an array of strings

    (I haven't tested it though!)

    Code:
    Private Sub Command1_Click()
    
    Dim fnum As Long
    Dim WholeFile As String
    Dim char As String
    Dim lines() As String
    Dim i As Integer
    Dim charPos As Integer
    Open "TESTFILE" For Binary As fnum ' Open file.
      WholeFile = Space(LOF(fnum))
      Get fnum, , WholeFile
    Close fnum
    
    charPos = InStr(WholeFile, Chr(10))
    While charPos <> 0
      charPos = InStr(WholeFile, Chr(10))
      ReDim Preserve lines(i + 1)
      lines(i) = Left(WholeFile, charPos - 1)
      'trim the text
      WholeFile = Mid(WholeFile, charPos + 1)
      i = i + 1
    Wend
    
    End Sub
    ------------------
    Mark Sreeves
    Analyst Programmer

    [email protected]
    A BMW Group Company



  3. #3
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845

    Post

    this should read the file into an array of strings

    (I haven't tested it though!)

    Code:
    Private Sub Command1_Click()
    
    Dim fnum As Long
    Dim WholeFile As String
    Dim char As String
    Dim lines() As String
    Dim i As Integer
    Dim charPos As Integer
    Open "TESTFILE" For Binary As fnum ' Open file.
      WholeFile = Space(LOF(fnum))
      Get fnum, , WholeFile
    Close fnum
    
    charPos = InStr(WholeFile, Chr(10))
    While charPos <> 0
      charPos = InStr(WholeFile, Chr(10))
      ReDim Preserve lines(i + 1)
      lines(i) = Left(WholeFile, charPos - 1)
      'trim the text
      WholeFile = Mid(WholeFile, charPos + 1)
      i = i + 1
    Wend
    
    End Sub
    ------------------
    Mark Sreeves
    Analyst Programmer

    [email protected]
    A BMW Group Company



  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    Calgary Alberta
    Posts
    359

    Post

    I'll try that. Thanks. What exactly does it do? Does it read the whole file into a string and then divide it or does it take a piece at a time?

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    Calgary Alberta
    Posts
    359

    Post

    It works great. I just dump lines() back into another file. I'm still wondering whether it dumps the entire file into memory (the string) or whether it only takes pieces of it.

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