Tab Delimited text file problem

DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Tab Delimited text file problem

  1. #1
    Join Date
    Aug 2005

    Tab Delimited text file problem

    I am downloading a tab delimited txt file when i am trying to parse the file using open function
    Open Destination & "csn.txt" For Input As #1
    Do While Not EOF(1)
        Line Input #1, NextLine              
        If NextLine <> "" Then
            arraydata =  split(NextLine)
            sSql = "insert into table"
            RunExecSQL sSql
        End If
    it takes entire file as a single line I have attached the sample file with this and also when i use recordset its working file but for large number of data it says script out of range please help me
    Attached Files Attached Files
    Last edited by Phil Weber; 08-10-2005 at 09:07 AM. Reason: Replaced font tags with code tags

  2. #2
    Join Date
    Nov 2003
    Portland, OR
    Line Input looks for a carriage return/line feed pair to indicate the end of each line; your file has only line feeds (Chr(10)), so you won't be able to use Line Input.

    If the file is small enough to read entirely into memory, you can do this:
    Dim Lines() As String
    Dim vLine As Variant
    Open Destination & "csn.txt" For Input As #1
    Do While Not EOF(1)
        Line Input #1, NextLine    
        If NextLine <> "" Then
            Lines = Split(NextLine, Chr(10))
            For Each vLine In Lines
                ArrayData =  Split(vLine)
                sSql = "insert into table"
                RunExecSQL sSql
        End If
    Phil Weber

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    Aug 2005
    Kent, England
    If the file is relatively small you can also try this code

    Dim strDataBuffer As String, strDataArray() As String
    Dim lngRow As Long
    ' Create buffer large enough to hold entire contents of file
    strDataBuffer = Space(FileLen(Destination & "csn.txt"))
    Open Destination & "csn.txt" For Binary As #1
    ' Load complete file into buffer
    Get #1, , strDataBuffer
    Close 1
    ' Remove any carriage return characters (if they exist)
    strDataBuffer = Replace(strDataBuffer, vbCr, "")
    ' Convert buffer contents into array
    strDataArray = Split(strDataBuffer, vbLf)
    ' Process array
    For lngRow = 0 To UBound(strDataArray)
       ' Process individual array items
    It will allow you to read in carriage return + linefeed formatted files (DOS/Windows) as well as linefeed only (UNIX) without needing to check beforehand.

Similar Threads

  1. Reading and writing lines from a text file...
    By Jenks in forum VB Classic
    Replies: 6
    Last Post: 05-24-2005, 02:22 PM
  2. wav file fade in out help
    By jase_dukerider in forum C++
    Replies: 2
    Last Post: 04-14-2005, 07:48 PM
  3. Replies: 2
    Last Post: 06-21-2003, 12:53 AM
  4. Script for scrolling
    By Mark in forum Web
    Replies: 3
    Last Post: 08-30-2001, 11:45 AM
  5. Problem: Reading text file with comma
    By Paolo in forum VB Classic
    Replies: 3
    Last Post: 01-08-2001, 08:59 AM

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
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

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