+ Reply to Thread
Results 1 to 16 of 16

Reading values from a text file

Hybrid View

krish T Reading values from a text... 10-18-2010, 01:16 PM
Leith Ross Re: Reading values from a... 10-18-2010, 01:18 PM
krish T Re: Reading values from a... 10-18-2010, 01:35 PM
krish T Re: Reading values from a... 10-18-2010, 10:02 PM
Leith Ross Re: Reading values from a... 10-18-2010, 11:12 PM
krish T Re: Reading values from a... 10-19-2010, 12:36 PM
krish T Re: Reading values from a... 10-19-2010, 09:29 PM
Leith Ross Re: Reading values from a... 10-19-2010, 09:55 PM
krish T Re: Reading values from a... 10-20-2010, 12:03 PM
Leith Ross Re: Reading values from a... 10-20-2010, 05:05 PM
krish T Re: Reading values from a... 10-21-2010, 11:10 AM
Leith Ross Re: Reading values from a... 10-21-2010, 11:16 AM
krish T Re: Reading values from a... 10-21-2010, 11:45 AM
krish T Re: Reading values from a... 10-21-2010, 11:54 AM
Leith Ross Re: Reading values from a... 10-21-2010, 12:38 PM
krish T Re: Reading values from a... 10-21-2010, 01:45 PM
  1. #1
    Forum Contributor
    Join Date
    10-01-2010
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    125

    Re: Reading values from a text file

    Hi Leith, Thanks for your quick response. Here the above code is giving the problem in the following loop:
         For r = 1 To count
          FileArray(r) = "req_par" & CStr(r) & ".txt"
        Next
    so I have changed the above code as below and it is working:
     Sub CopyFilesToArray()
    
      Dim Data As Variant
      Dim FileData() As Variant
      Dim FileArray As Variant
      Dim FileName As Variant
      Dim FilePath As String
      Dim I As Long, J As Long
      Dim req_par(1 To 50) As String
      
        count = 2
        
        ReDim FileArray(count - 1) 
        
        FilePath = "C:\"
    
        For r = 0 To count - 1
        FileArray(r) = "req_par" & CStr(r + 1) & ".txt"
        Next
        
        ReDim FileData(1 To 50, 1 To UBound(FileArray) + 1)
    
        For Each FileName In FileArray
            J = J + 1
            FileName = FilePath & FileName
            Open FileName For Input As #1
              Do While Not EOF(1)
                I = I + 1
                Input #1, Data
                FileData(I, J) = Data
              Loop
            Close #1
            I = 0
          Next FileName
          
    End Sub
    Thanks
    Krish T

  2. #2
    Forum Contributor
    Join Date
    10-01-2010
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    125

    Re: Reading values from a text file

    You are genius Leith. Solved my problem. Thanks a lot. Really helpful to me.

    Thanks
    Krish T

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Reading values from a text file

    Hello Krish T,

    Sorry about the oversight on the loop indices. I thought I had changed them. Glad to know it is working.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  4. #4
    Forum Contributor
    Join Date
    10-01-2010
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    125

    Re: Reading values from a text file

    No problem Leith. Once again Thanks to you.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1