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
|