Mombu the Microsoft Forum sponsored links

Go Back   Mombu the Microsoft Forum > Microsoft > problem reading text file using a loop
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 21st April 02:51
himesh patel
External User
 
Posts: 1
Default problem reading text file using a loop



Hi i am new to VBScript and i was wondering if someone could please take a
look at my code and tell me what wrong with it.

In the file text file from which the loop reads i have several different
news items but only the last one seem to be displayed un the html file. Can
someone please help and tell me what i must do to get my script to read all
the news items.

Thank you

Himesh

dim filesys, filetxt, fileHandle, fileout
dim line, newsheading, filename, endnews, newline
Const ForReading = 1
Const ForWriting = 2
newline = chr(13) + chr(10)
Set filesys = CreateObject("Scripting.FileSystemObject")
Set filetxt = filesys.OpenTextFile("C:\vbscript\newsitems.txt", ForReading,
false )
line = filetxt.readline
Do until filetxt.AtEndOfStream

tag = mid( line, 1, len( "<NEWSHEADING>" ) )

if tag = "<NEWSHEADING>" then
readnews line
else
line = filetxt.readline
end if
loop

filetxt.Close
msgbox "Page has Created"
sub readNews( line )
dim tag

line = filetxt.readline
filename = mid( line, len("<FILENAME>" ) + 1 )

Set fileHandle = CreateObject("Scripting.FileSystemObject")
Set fileout = fileHandle.OpenTextFile("C:\vbscript\midtest.html" ,
ForWriting, true )

line = filetxt.readline

tag = mid( line, 1, len( "<ENDNEWS>" ) )

do until tag = "<ENDNEWS>"

' we now process all the lines in the news and write to new HTML file

fileout.Writeline( line )

' Read a line and extract a tag.
line = filetxt.readline
tag = mid( line, 1, len( "<ENDNEWS>" ) )

loop
fileout.close
end sub
  Reply With Quote


  sponsored links


2 21st April 02:51
geir klemetsen
External User
 
Posts: 1
Default problem reading text file using a loop



The constant VbCrLf does the job. better.

Example:
msgbox "First line of text" & VbCrLf & "Next line of text"
  Reply With Quote
Reply


Thread Tools
Display Modes




Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666