Home |
Search |
Today's Posts |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Extra Lines Inserted in Multi-Line Chart Titles | Charts and Charting in Excel | |||
To add extra line/lines to single cell in Excel spreadsheet | New Users to Excel | |||
How do I add an extra line to a line-column chart? | Charts and Charting in Excel | |||
line input problem-need to return 5 lines after a string is found | Excel Programming | |||
Excel 2000 Hanging while reading large file with Line Input | Excel Programming |