LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Line Input is reading extra lines?

Il giorno sabato 14 marzo 2015 01:24:21 UTC+1, Robert Crandal ha scritto:
So, I've been playing with the "Line Input" command to test
reading from text files. I am reading and displaying each
paragraph with a MsgBox. If there are only 2 paragraphs
in my input, why is a MsgBox appearing 4 times?

It actually prints 2 empty Msgbox windows, so does that
mean my input has extra CR or LF characters? Do I
need to filter out blank lines? (P.S: I know Gary showed
me a filter function, but that worked with a different
type of variable.)

Here is my sample text data:

'--------------------begin "inp.txt"------------------------
Depart do be so he enough talent. Sociable formerly six but handsome. Up do
view time they shot. He concluded disposing provision by questions as
situation. Its estimating are motionless day sentiments end. Calling an
imagine at forbade. At name no an what like spot. Pressed my by do affixed
he studied.

The him father parish looked has sooner. Attachment frequently gay
terminated son. You greater nay use prudent placing. Passage to so distant
behaved natural between do talking. Friends off her windows painful. Still
gay event you being think nay for. In three if aware he point it. Effects
warrant me by no on feeling settled resolve.
'--------------------end "inp.txt"------------------------

Here is my code:

Sub myImportTxt()

Dim sFile As String
Dim sLine As String
Dim f As Integer

f = FreeFile()
sFile = "inp.txt"

Open sFile For Input As #f

Do Until EOF(f)
Line Input #f, sLine
MsgBox sLine ' MsgBox shows 4 times?
Loop ' Why? How fix?

Close #f

End Sub


Hi Robert,

try:

Public Sub Test()
Const cstrPath = "D:\"
Const cstrFile = "Line Input is reading extra lines.txt"
Dim ff As Integer
Dim s() As String
Dim i As Long

ff = FreeFile(0)
Open cstrPath & cstrFile For Input Access Read As ff
s = Split(Input$(LOF(ff), #ff), vbNewLine)
Close

Debug.Print "Items : "; UBound(s) + 1

For i = LBound(s) To UBound(s)
If Len(s(i)) Then Debug.Print s(i)
Next

End Sub

--
Ciao!
Maurizio
 
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
Extra Lines Inserted in Multi-Line Chart Titles Stuart Bratesman Charts and Charting in Excel 1 December 23rd 08 05:56 AM
To add extra line/lines to single cell in Excel spreadsheet Helen New Users to Excel 3 January 13th 08 11:23 PM
How do I add an extra line to a line-column chart? moose Charts and Charting in Excel 1 February 23rd 06 05:30 PM
line input problem-need to return 5 lines after a string is found festdaddy Excel Programming 3 December 8th 05 04:38 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 07:20 AM.

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

About Us

"It's about Microsoft Excel"