open a text file and only use lines that start with a number, then wri

open a text file and only use lines that start with a number, then wri

Page 1 of 1

2 Replies - 2181 Views - Last Post: 21 September 2010 - 11:04 AM Rate Topic: -----

#1 Ianm1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 21-September 10

open a text file and only use lines that start with a number, then wri

Posted 21 September 2010 - 04:11 AM

I need to read an import text file via VB or VBA only select lines that start with a number and write those lines to a new file

I have looked at Streamreader/streamwriter but cannot understand the way to select the line
Is This A Good Question/Topic? 0
  • +

Replies To: open a text file and only use lines that start with a number, then wri

#2 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 465
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: open a text file and only use lines that start with a number, then wri

Posted 21 September 2010 - 04:27 AM

streamreader/writer is VB.NET. but there is a tutorial about reading text file line by line in our tutorial section under vb6 section
Was This Post Helpful? 0
  • +
  • -

#3 parbipin  Icon User is offline

  • D.I.C Head

Reputation: 29
  • View blog
  • Posts: 95
  • Joined: 23-August 10

Re: open a text file and only use lines that start with a number, then wri

Posted 21 September 2010 - 11:04 AM

This is not the complete code and also not tested. It reads a line and stores it in variable tLine. You would then need to apply your logic around if you wanna use that line or not. Also, How do you wanna use it.


Dim FileNum As Integer, tLine As String, LogFileName as String

LogFileName = "Complete path to your Text File"

    FileNum = FreeFile ' next file number
    Open LogFileName For Input Access Read Shared As #FileNum ' open the file for reading
    Do While Not EOF(FileNum)
        Line Input #FileNum, tLine ' read a line from the text file
    Loop ' until the last line is read
    Close #FileNum ' close the file


Hope it helps!!!!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1