Forums
This topic is locked
Problems reading from a text file
Posted 24 Aug 2007 18:45:54
1
has voted
24 Aug 2007 18:45:54 Michelle Weiler posted:
The script I am using is wanting to read the whole file and not 1 line at a time. Can someone please help here is the code I am using and it will not hold onto one donor # at a time. I put a response.write code in to see what was happening and it is reading the whole file as one line.<%
' Set up constants
Const ForReading = 1
Const Create = False
' Declare local variables
Dim objFSO ' FileSystemObject
Dim TS ' TextStreamObject
Dim strLine ' local variable to store Line
Dim strFileName ' local variable to store fileName
Dim SubString
strFileName = Server.MapPath("\refmgfile.txt"
' Instantiate the FileSystemObject
Set objFSO = Server.CreateObject("Scripting.FileSystemObject"
' use Opentextfile Method to Open the text File
Set TS = objFSO.OpenTextFile(strFileName, ForReading, Create)
If Not TS.AtEndOfStream Then
Do While Not TS.AtendOfStream
strLine = TS.ReadLine ' Read one line at a time
hldstrLine = left(strLine,9)
hlddonor = Request.Form("donor"
'Response.Write("donor# = " & hldstrLine)
If Request.Form("donor" = hldstrLine then
valdiscount = "Y"
else
valdiscount = ""
end if
Loop
End If
' close TextStreamObject
' and destroy local variables to relase memory
TS.Close
Set TS = Nothing
Set objFSO = Nothing
%>
Thanks in advance.
Replies
Replied 28 Aug 2007 15:08:23
28 Aug 2007 15:08:23 Georgi Kralev replied:
Hi Michelle,
The following piece of code that you use:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote> strLine = TS.ReadLine ' Read one line at a time<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
Should return only one line from the TextStream. Therefore, I believe that the problem is in your file (not with your code).
Check your file.
I hope this helps you.
Regards,
Georgi Kralev
----------------------------------
Support - www.DMXzone.com
The following piece of code that you use:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote> strLine = TS.ReadLine ' Read one line at a time<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
Should return only one line from the TextStream. Therefore, I believe that the problem is in your file (not with your code).
Check your file.
I hope this helps you.
Regards,
Georgi Kralev
----------------------------------
Support - www.DMXzone.com