Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Reading a text file line by line

Hi there,

I'm trying to loop through a text file, processing each line of the file
depending on the values it contains.

Here's what I've got so far, all those bits don't need to be per line, they
apply to the whole file.

So my question is, how can I loop on the line number of the file?

Sub fdsa()
Dim FileNumber As Integer, FileLength As Integer, FilePath As String,
FullString As String
FilePath = "C:\The Export 2.txt"
FileNumber = FreeFile
Open FilePath For Input As FileNumber
FileLength = LOF(FileNumber)

FullString = Input(FileLength, FileNumber)
MsgBox FullString, vbInformation + vbOKOnly

FullString = Replace(FullString, Chr(9), "")
MsgBox FullString, vbInformation + vbOKOnly

FullString = Replace(FullString, ".00", "")
MsgBox FullString, vbInformation + vbOKOnly

Close #FileNumber
End Sub


Cheers,
Foss
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Reading a text file line by line

Sub fdsa()
Dim FileNumber As Integer, FilePath As String
Dim FullString As String
FilePath = "C:\The Export 2.txt"
FileNumber = FreeFile
Open FilePath For Input As #FileNumber
FileLength = LOF(FileNumber)
Do While Not EOF(FileNumber)
Line Input #FileNumber, FullString
MsgBox FullString, vbInformation + vbOKOnly

Loop
Close #FileNumber
End Sub

--
Regards,
Tom Ogilvy



"Foss" wrote in message
...
Hi there,

I'm trying to loop through a text file, processing each line of the file
depending on the values it contains.

Here's what I've got so far, all those bits don't need to be per line,

they
apply to the whole file.

So my question is, how can I loop on the line number of the file?

Sub fdsa()
Dim FileNumber As Integer, FileLength As Integer, FilePath As String,
FullString As String
FilePath = "C:\The Export 2.txt"
FileNumber = FreeFile
Open FilePath For Input As FileNumber
FileLength = LOF(FileNumber)

FullString = Input(FileLength, FileNumber)
MsgBox FullString, vbInformation + vbOKOnly

FullString = Replace(FullString, Chr(9), "")
MsgBox FullString, vbInformation + vbOKOnly

FullString = Replace(FullString, ".00", "")
MsgBox FullString, vbInformation + vbOKOnly

Close #FileNumber
End Sub


Cheers,
Foss



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Reading a text file line by line

Tom,

Thanks very much! That's superb!

Cheers,
Pete

"Tom Ogilvy" wrote:

Sub fdsa()
Dim FileNumber As Integer, FilePath As String
Dim FullString As String
FilePath = "C:\The Export 2.txt"
FileNumber = FreeFile
Open FilePath For Input As #FileNumber
FileLength = LOF(FileNumber)
Do While Not EOF(FileNumber)
Line Input #FileNumber, FullString
MsgBox FullString, vbInformation + vbOKOnly

Loop
Close #FileNumber
End Sub

--
Regards,
Tom Ogilvy



"Foss" wrote in message
...
Hi there,

I'm trying to loop through a text file, processing each line of the file
depending on the values it contains.

Here's what I've got so far, all those bits don't need to be per line,

they
apply to the whole file.

So my question is, how can I loop on the line number of the file?

Sub fdsa()
Dim FileNumber As Integer, FileLength As Integer, FilePath As String,
FullString As String
FilePath = "C:\The Export 2.txt"
FileNumber = FreeFile
Open FilePath For Input As FileNumber
FileLength = LOF(FileNumber)

FullString = Input(FileLength, FileNumber)
MsgBox FullString, vbInformation + vbOKOnly

FullString = Replace(FullString, Chr(9), "")
MsgBox FullString, vbInformation + vbOKOnly

FullString = Replace(FullString, ".00", "")
MsgBox FullString, vbInformation + vbOKOnly

Close #FileNumber
End Sub


Cheers,
Foss




  #4   Report Post  
Posted to microsoft.public.excel.programming
Ed Ed is offline
external usenet poster
 
Posts: 399
Default Reading a text file line by line

Foss:

I would consider using Word rather than Excel. If you opened the document
in Word, the Word object model allows you to select a line at a time. Word
also has a built-in EndOfDocument (EndOfFFile ??) bookmark; you can use this
to loop through -
Do
Select Line
Code Here
Loop Until End bookmark found.

HTH
Ed

"Foss" wrote in message
...
Hi there,

I'm trying to loop through a text file, processing each line of the file
depending on the values it contains.

Here's what I've got so far, all those bits don't need to be per line,

they
apply to the whole file.

So my question is, how can I loop on the line number of the file?

Sub fdsa()
Dim FileNumber As Integer, FileLength As Integer, FilePath As String,
FullString As String
FilePath = "C:\The Export 2.txt"
FileNumber = FreeFile
Open FilePath For Input As FileNumber
FileLength = LOF(FileNumber)

FullString = Input(FileLength, FileNumber)
MsgBox FullString, vbInformation + vbOKOnly

FullString = Replace(FullString, Chr(9), "")
MsgBox FullString, vbInformation + vbOKOnly

FullString = Replace(FullString, ".00", "")
MsgBox FullString, vbInformation + vbOKOnly

Close #FileNumber
End Sub


Cheers,
Foss



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Reading a text file line by line

Ed,

Thanks very much, although to be honest it wasn't intended to run in either.
It'll be running in Business Objects. I was posting here because I always get
the answers I want!

Thanks though, I'll use that one in Word next time I need to.

Cheers,
Pete

"Ed" wrote:

Foss:

I would consider using Word rather than Excel. If you opened the document
in Word, the Word object model allows you to select a line at a time. Word
also has a built-in EndOfDocument (EndOfFFile ??) bookmark; you can use this
to loop through -
Do
Select Line
Code Here
Loop Until End bookmark found.

HTH
Ed

"Foss" wrote in message
...
Hi there,

I'm trying to loop through a text file, processing each line of the file
depending on the values it contains.

Here's what I've got so far, all those bits don't need to be per line,

they
apply to the whole file.

So my question is, how can I loop on the line number of the file?

Sub fdsa()
Dim FileNumber As Integer, FileLength As Integer, FilePath As String,
FullString As String
FilePath = "C:\The Export 2.txt"
FileNumber = FreeFile
Open FilePath For Input As FileNumber
FileLength = LOF(FileNumber)

FullString = Input(FileLength, FileNumber)
MsgBox FullString, vbInformation + vbOKOnly

FullString = Replace(FullString, Chr(9), "")
MsgBox FullString, vbInformation + vbOKOnly

FullString = Replace(FullString, ".00", "")
MsgBox FullString, vbInformation + vbOKOnly

Close #FileNumber
End Sub


Cheers,
Foss




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Challenge - Excel Line Feed Character CHR(10) - How to Delete and keep the text formatting without going ro single line in a cell ? No Name Excel Worksheet Functions 7 October 7th 09 11:10 AM
A 2 line text showing up in the Cell in Excel prints in 1 line Danny Excel Discussion (Misc queries) 6 July 12th 05 08:47 PM
import huge text file line-by-line? rachel Excel Programming 2 November 6th 04 04:43 PM
Reads entire *.txt file into string opposed to a desired line by line input. ej_user Excel Programming 3 October 11th 04 07:15 PM
Excel 2000 Hanging while reading large file with Line Input Jacques Brun Excel Programming 4 February 21st 04 05:05 PM


All times are GMT +1. The time now is 04:56 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"