Problem: Reading text file with comma


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Problem: Reading text file with comma

  1. #1
    Paolo Guest

    Problem: Reading text file with comma


    Hi
    I've this problem:
    I read a text file and generate a text file.
    Example
    Source file:
    ----------
    Hi
    I come from Rome, but I live in Turin
    Bye
    ---------
    Destination file
    ----------
    HTML = ""
    HTML = HTML & "Hi"
    HTML = HTML & "I come from Rome, but I live in Turin"
    HTML = HTML & "Bye"
    ---------

    but when I open the source file
    and read each row for time
    my program reads the sorce file so:

    Hi
    I come from Rome
    but I live in Turin
    Bye

    With 4 rows instead of 3, it trasforms comma in EOL.

    My code:
    While Not EOF(iFile)
    Input #iFile, sRow
    Call WorkOnIt(sRow)
    Wend

    Someone can help me?
    Tanks



  2. #2
    Craig Brown Guest

    Re: Problem: Reading text file with comma


    Paulo,

    I suspect that your input statement is interpreting the comma as an end of
    field delimeter.

    Try putting a breakpoint on Call WorkOnIt(sRow) and checking the contents
    of sRow.

    Let us know how it works out.

    Craig Brown

    PS. What's the weather like in Turino now?


    "Paolo" <p.dellaposta@reply.it> wrote:
    >
    >Hi
    >I've this problem:
    >I read a text file and generate a text file.
    >Example
    >Source file:
    >----------
    >Hi
    >I come from Rome, but I live in Turin
    >Bye
    >---------
    >Destination file
    >----------
    >HTML = ""
    >HTML = HTML & "Hi"
    >HTML = HTML & "I come from Rome, but I live in Turin"
    >HTML = HTML & "Bye"
    >---------
    >
    >but when I open the source file
    >and read each row for time
    >my program reads the sorce file so:
    >
    >Hi
    >I come from Rome
    >but I live in Turin
    >Bye
    >
    >With 4 rows instead of 3, it trasforms comma in EOL.
    >
    >My code:
    > While Not EOF(iFile)
    > Input #iFile, sRow
    > Call WorkOnIt(sRow)
    > Wend
    >
    >Someone can help me?
    >Tanks
    >
    >



  3. #3
    Kevin Guest

    Re: Problem: Reading text file with comma


    Try using Line Input instead of Input. It reads data until it encounters a
    carriage return.

    Example
    Dim TextLine
    Open "TESTFILE" For Input As #1 ' Open file.
    Do While Not EOF(1) ' Loop until end of file.
    Line Input #1, TextLine ' Read line into variable.
    Debug.Print TextLine ' Print to the Immediate window.
    Loop
    Close #1 ' Close file.

    Kevin

    "Craig Brown" <brown.c3@aetna.com> wrote:
    >
    >Paulo,
    >
    >I suspect that your input statement is interpreting the comma as an end

    of
    >field delimeter.
    >
    >Try putting a breakpoint on Call WorkOnIt(sRow) and checking the contents
    >of sRow.
    >
    >Let us know how it works out.
    >
    >Craig Brown
    >
    >PS. What's the weather like in Turino now?
    >
    >
    >"Paolo" <p.dellaposta@reply.it> wrote:
    >>
    >>Hi
    >>I've this problem:
    >>I read a text file and generate a text file.
    >>Example
    >>Source file:
    >>----------
    >>Hi
    >>I come from Rome, but I live in Turin
    >>Bye
    >>---------
    >>Destination file
    >>----------
    >>HTML = ""
    >>HTML = HTML & "Hi"
    >>HTML = HTML & "I come from Rome, but I live in Turin"
    >>HTML = HTML & "Bye"
    >>---------
    >>
    >>but when I open the source file
    >>and read each row for time
    >>my program reads the sorce file so:
    >>
    >>Hi
    >>I come from Rome
    >>but I live in Turin
    >>Bye
    >>
    >>With 4 rows instead of 3, it trasforms comma in EOL.
    >>
    >>My code:
    >> While Not EOF(iFile)
    >> Input #iFile, sRow
    >> Call WorkOnIt(sRow)
    >> Wend
    >>
    >>Someone can help me?
    >>Tanks
    >>
    >>

    >



  4. #4
    codemasterj Guest

    Re: Problem: Reading text file with comma


    You could also try using the FileSystemObject.
    It's a bit more forgiving and comma delimiters are not
    necessary as you can read line by line (each line
    being terminated by a carriage return (chr(13)):

    Set fs = ServerCreate("Scripting.FileSystemObject")
    set file = fs.OpenTextStream("filename", ForReading)

    HTML = ""

    While not file.eof

    set intext = file.ReadLine

    if not file.eof then 'since we could hit the eof marker here

    HTML = HTML & intext

    end if

    wend

    file.close

    set file = nothing
    set fs = nothing


    "Paolo" <p.dellaposta@reply.it> wrote:
    >
    >Hi
    >I've this problem:
    >I read a text file and generate a text file.
    >Example
    >Source file:
    >----------
    >Hi
    >I come from Rome, but I live in Turin
    >Bye
    >---------
    >Destination file
    >----------
    >HTML = ""
    >HTML = HTML & "Hi"
    >HTML = HTML & "I come from Rome, but I live in Turin"
    >HTML = HTML & "Bye"
    >---------
    >
    >but when I open the source file
    >and read each row for time
    >my program reads the sorce file so:
    >
    >Hi
    >I come from Rome
    >but I live in Turin
    >Bye
    >
    >With 4 rows instead of 3, it trasforms comma in EOL.
    >
    >My code:
    > While Not EOF(iFile)
    > Input #iFile, sRow
    > Call WorkOnIt(sRow)
    > Wend
    >
    >Someone can help me?
    >Tanks
    >
    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center