Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default read multiple line


How can I read a mulitple line in a text file and then print it as
single line?

eg...

she is
beautiful

output as...

she is beautifu

--
JaiJa
-----------------------------------------------------------------------
JaiJai's Profile: http://www.excelforum.com/member.php...fo&userid=1948
View this thread: http://www.excelforum.com/showthread.php?threadid=48388

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default read multiple line

a = "She is"
b = "beautiful"
msgbox a & " " & b

--
Regards,
Tom Ogilvy


"JaiJai" wrote in
message ...

How can I read a mulitple line in a text file and then print it as a
single line?

eg...

she is
beautiful

output as...

she is beautiful


--
JaiJai
------------------------------------------------------------------------
JaiJai's Profile:

http://www.excelforum.com/member.php...o&userid=19484
View this thread: http://www.excelforum.com/showthread...hreadid=483888



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default read multiple line


No, I need to write a vba like

open ObjOut For Output As #2
Line Input #1, data
Close

don't want to use msgbox....

since the input text file is not really simply,it may vary in number of
lines....


--
JaiJai
------------------------------------------------------------------------
JaiJai's Profile: http://www.excelforum.com/member.php...o&userid=19484
View this thread: http://www.excelforum.com/showthread...hreadid=483888

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default read multiple line


the input file is

can i write print file as follows:

Open textfile For Output As #2

TextToFind = "greece"
Do While Not EOF(1)
Line Input #1, data
If InStr(1, data, TextToFind) Then
Print #2, data
End If
Loop
Close

the input textfile file is

"fdsfsdfsdf
fdsgfsdfsdf
dfssafsdf
greece gree tyyyy
iolololololololo"

i want the output file is

greece gree tyyyy iolololololololo

I want to print file from "greece" and print the rest of files a
SINGLE line

--
JaiJa
-----------------------------------------------------------------------
JaiJai's Profile: http://www.excelforum.com/member.php...fo&userid=1948
View this thread: http://www.excelforum.com/showthread.php?threadid=48388

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default read multiple line


besides, how can i print out "greece gree tyyyy iolololololololo" in the
first line of the output text file BUT the original output text file has
letters already.
I don't want the original letters being removed but instead just insert
"greece gree tyyyy iolololololololo" in the first line.


--
JaiJai
------------------------------------------------------------------------
JaiJai's Profile: http://www.excelforum.com/member.php...o&userid=19484
View this thread: http://www.excelforum.com/showthread...hreadid=483888



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default read multiple line


anyone can help?
it is very urgen

--
JaiJa
-----------------------------------------------------------------------
JaiJai's Profile: http://www.excelforum.com/member.php...fo&userid=1948
View this thread: http://www.excelforum.com/showthread.php?threadid=48388

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default read multiple line

In the example
Source.txt contains the line with Greece in it
Source1.txt is the data that will be placed after the concatenated Greece
line
in a new file
Dest.Txt is the new file that will contained the joined data set.


Sub AdjustFiles()

Dim SourceNum As Integer
Dim DestNum As Integer
Dim SourceNum1 as Integer
Dim bFound as Boolean
Dim Temp As String

' If an error occurs, close the files
' and end the macro.
On Error GoTo ErrHandler

' Open the destination text file.
DestNum = FreeFile()
Open "DEST.TXT" For Output As DestNum

' Open the source text file.
SourceNum = FreeFile()
Open "SOURCE.TXT" For Input As SourceNum

SourceNum1 = FreeFile()
Open "SOURCE1.TXT" For Input As SourceNum

bFound = False
Do While Not EOF(SourceNum)
Line Input #SourceNum, Temp

If InStr(1, Temp, "greece", vbTextCompare) Then
sStr = Temp & " "
Elseif bFound
sStr = sStr & Temp
' write concatenated data to Dest.txt
Print #DestNum, sStr
' quit reading from Source.Txt
Exit Do
End If
Loop

' now append data from Source1.txt to DEST.txt
Do While Not EOF(SourceNum1)
Line Input #SourceNum1, Temp
Print #DestNum, Temp
Loop


CloseFiles:

' Close the destination file and the source file.
Close #DestNum
Close #SourceNum
Close #SourceNum1
Exit Sub

ErrHandler:

MsgBox "Error # " & Err & ": " & Error(Err)
Resume CloseFiles

End Sub

Once you are sure it does what you want, you can then add code to delete
Source1.txt and rename Dest.txt to Source1.txt

--
Regards,
Tom Ogilvy




"JaiJai" wrote in
message ...

anyone can help?
it is very urgent


--
JaiJai
------------------------------------------------------------------------
JaiJai's Profile:

http://www.excelforum.com/member.php...o&userid=19484
View this thread: http://www.excelforum.com/showthread...hreadid=483888



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default read multiple line


thanks a lot but one more thing he

Is there any scripts for inserting the target line in the orginal tex
file?

that is :

target statement is "greece"

The original text output file is:

fsdfsfsf
gdfgs
dfsafdgfd

After running the scripts, then the output text file is (while keepin
the original content):

greece
fsdfsfsf
gdfgs
dfsafdgf

--
JaiJa
-----------------------------------------------------------------------
JaiJai's Profile: http://www.excelforum.com/member.php...fo&userid=1948
View this thread: http://www.excelforum.com/showthread.php?threadid=48388

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default read multiple line


is it that no method for inserting the statement into a textfile
(original has content)?
I just keep the remaining and original content in the text file but
with a new statement inserted in the first line in this output file.


--
JaiJai
------------------------------------------------------------------------
JaiJai's Profile: http://www.excelforum.com/member.php...o&userid=19484
View this thread: http://www.excelforum.com/showthread...hreadid=483888

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default read multiple line

Can you insert a line at the top of an existing text file that has no
specific structure.
No. You would have to write the combined file, then copy it back over the
original.


--
Regards,
Tom Ogilvy

"JaiJai" wrote in
message ...

is it that no method for inserting the statement into a textfile
(original has content)?
I just keep the remaining and original content in the text file but
with a new statement inserted in the first line in this output file.


--
JaiJai
------------------------------------------------------------------------
JaiJai's Profile:

http://www.excelforum.com/member.php...o&userid=19484
View this thread: http://www.excelforum.com/showthread...hreadid=483888





  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default read multiple line

Try the following code:



Dim InFNum As Integer: InFNum = 1
Dim OutFNum As Integer: OutFNum = 2
Dim OutFName As String
Dim InFName As String
Dim S As String
Dim WholeS As String

InFName = "H:\test.txt" '<< Change
OutFName = "H:\out.txt" '<< Change
Open InFName For Input As InFNum
Do Until EOF(InFNum)
Line Input #InFNum, S
WholeS = WholeS & S
Loop
Close InFNum
Open OutFName For Output As OutFNum
Print #OutFNum, WholeS
Close OutFNum




--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com

"JaiJai"
wrote in message
...

How can I read a mulitple line in a text file and then print it
as a
single line?

eg...

she is
beautiful

output as...

she is beautiful


--
JaiJai
------------------------------------------------------------------------
JaiJai's Profile:
http://www.excelforum.com/member.php...o&userid=19484
View this thread:
http://www.excelforum.com/showthread...hreadid=483888



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
Can Macro read line graphs? WH99 Excel Discussion (Misc queries) 2 October 10th 08 03:51 PM
Can Macro read line graphs? WH99 Charts and Charting in Excel 2 October 10th 08 03:49 PM
Read only command line switch Mike K Excel Discussion (Misc queries) 2 January 2nd 05 03:57 PM
Textbox-read text line by line antonio Excel Programming 0 October 26th 04 05:42 PM
read last line of a file Mike[_49_] Excel Programming 4 November 25th 03 10:41 PM


All times are GMT +1. The time now is 02:41 PM.

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"