Results 1 to 2 of 2

Thread: Getting data from text files

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    1

    Question Getting data from text files

    Hi, I am new to .net vb programing and wanted help in the code for getting data from text files.

    I have about 200 .txt files, all in same format as below.

    m 998718989898
    m 998766990878
    F 67
    P Thane

    So, I want to import this in excel. I know the code for inserting the data in Excel, but no idea of getting the data from text files. This text files are actually used as contact management by the co and has contact name as file name.

    Please help by providing code for getting data from a single file, Then I will run it in loop and insert in Excel.

    Thanking in advance

  2. #2
    Frenzied Member dolot's Avatar
    Join Date
    Nov 2007
    Location
    Music city, U.S.A.
    Posts
    1,253

    Re: Getting data from text files

    Something like:

    Code:
      
                    'open the file
                    Dim Lines As String() = IO.File.ReadAllLines("c:\mytestfile.txt")  'whatever file you want to read.
                    Dim Items As String()
    
                    'loop through all the lines
                    For I As Integer = 0 To Lines.Length - 1
    
                        'split the line using whatever delimiter the file has
                        Items = Split(Lines(I), ",")
            
                        'use the items array for whatever you want.
    
                    Next I
    I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
    My war with a browser-redirect trojan

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