From: Ogier on 22 Sep 2009 09:29 I have a text file containing the following four lines: This line has no commas. However, this one has But, alas, the line is read in pieces Characters: ;_.+"%&!,,, If I try to read it with the following sub Private Sub ReadTextFile() Dim FileName As String Dim Line As String FileName = "Y:\TestTextWithCommas.txt" Open FileName For Input As #1 Do Until EOF(1) Input #1, Line Debug.Print Line Loop Close #1 End Sub The result in the Immediate window is this: This line has no commas. However this one has But alas the line is read in pieces Characters: ;_.+"%&! [Three empty lines follow] What is the reason for this strange behavior and how do I avoid it? Best wishes Holger Nielsen
From: Jay Freedman on 22 Sep 2009 10:25 Change your code from Input #1, Line to Line Input #1, Line From the help topic, "The Line Input # statement reads from a file one character at a time until it encounters a carriage return (Chr(13)) or carriage return-linefeed (Chr(13) + Chr(10)) sequence." In contrast, the Input # statement is meant to read comma-delimited data created by the Write # statement. It isn't appropriate for the sort of data you're trying to read. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. Ogier wrote: > I have a text file containing the following four lines: > > This line has no commas. > However, this one has > But, alas, the line is read in pieces > Characters: ;_.+"%&!,,, > > If I try to read it with the following sub > > Private Sub ReadTextFile() > Dim FileName As String > Dim Line As String > FileName = "Y:\TestTextWithCommas.txt" > Open FileName For Input As #1 > Do Until EOF(1) > Input #1, Line > Debug.Print Line > Loop > Close #1 > End Sub > > The result in the Immediate window is this: > > This line has no commas. > However > this one has > But > alas > the line is read in pieces > Characters: ;_.+"%&! > [Three empty lines follow] > > What is the reason for this strange behavior and how do I avoid it? > > Best wishes > Holger Nielsen
From: Ogier on 22 Sep 2009 11:32 "Jay Freedman" skrev: > Change your code from > > Input #1, Line > > to > > Line Input #1, Line > Thank you very much. Holger
|
Pages: 1 Prev: Office 2007 and Office 2003 and word macros. Next: Creating a master document from code |