Results 1 to 3 of 3
  1. #1
    craig1988 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Aug 2014
    Posts
    82

    EOF not correctly identifying the correct data. Issue with LF's

    Hi all

    I am trying to read a text file into an array, however the EOF appears to be stopping before the End of File...



    I have figured out that each line of the text file is finished with a LF and I think I need a CRLF for the EOF to recognise further data.

    I am using the code below which catered for the same input text file with a CRLF at the end of each line.

    I suppose I am trying to replace the LF's with CRLF's. Is there any way to manipulate the below code?

    Code:
    iFileNum = FreeFile
    Open FileName For Input As iFileNum
                
    x = 0
    ReDim Preserve sLine(x)
                
    Do Until EOF(iFileNum)
        Line Input #iFileNum, sLine(x)
        x = x + 1
        ReDim Preserve sLine(x)
    Loop
    Close iFileNum

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,816
    Review https://answers.microsoft.com/en-us/...b-64a8e146a7e9

    Code uses Split() function to parse string to an array.
    Code:
    Public Sub ImportTextFile_new()
         Dim the_file As String
         Dim LineData As String
         Dim ICDraw As String
         Dim cnn As ADODB.Connection
         Dim rs As ADODB.Recordset
         Dim strSQL As String
         Dim x As Integer
         Dim aryICDraw As Variant
         Set cnn = CurrentProject.Connection
         Set rs = New ADODB.Recordset
         ' Open the text file
         the_file = open_dialog
         Open the_file For Input As #1
         ' Open the table to insert the text file into
         strSQL = "Select * from local_file"
         rs.Open strSQL, cnn, adOpenDynamic, adLockOptimistic
         ' Read a line of data.
         Line Input #1, LineData
         ICDraw = Trim(LineData)
         Close #1
         aryICDraw = Split(ICDraw, vbLf)
         For x = 0 To UBound(aryICDraw)
             rs.AddNew
             rs!the_code = aryICDraw(x)
             rs.Update
         Next x
         Set rs = Nothing
         Set cnn = Nothing
    End Sub
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    I question the use of iFileNum as a variable but trying to use Input against #iFileNum. Would think they should be the same name. Then again, you say it works elsewhere...
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 17
    Last Post: 08-28-2017, 06:25 PM
  2. Replies: 10
    Last Post: 06-03-2013, 10:24 AM
  3. Replies: 11
    Last Post: 04-19-2012, 03:28 PM
  4. Can System Restore correct Form Size issue
    By fordtough in forum Forms
    Replies: 0
    Last Post: 04-12-2011, 02:56 PM
  5. Identifying new data
    By manicamaniac in forum Programming
    Replies: 5
    Last Post: 04-28-2010, 11:08 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
  •  
Other Forums: Microsoft Office Forums