<%
Const Filename = "/readme.txt" ' file to read
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
' Create a filesystem object
Dim FSO
set FSO = server.createObject("Scripting.FileSystemObject")
Dim Filepath
Filepath = Server.MapPath(Filename)
if FSO.FileExists(Filepath) Then
Dim file
set file = FSO.GetFile(Filepath)
Dim FileSize
FileSize = file.Size
' Open the file
Dim TextStream
Set TextStream = file.OpenAsTextStream(ForReading, _
TristateUseDefault)
' Read the file line by line
Do While Not TextStream.AtEndOfStream
dim Line
Line = TextStream.readline
if not Instr(Line,"TV") then response.Write Line & vbcrlf
Loop
Set TextStream = nothing
End If
Set FSO = nothing
%>
Feltyp:
Körningsfel i Microsoft VBScript (0x800A0005)
Ogiltigt proceduranrop eller argument.
/textfil/default.asp, line 28
På denna koden:
Rad28 = Set TextStream = file.OpenAsTextStream(ForReading, TristateUseDefault)
<form name="do" method="post" action="default.asp?do=CreateThatCoolTextFile">
Välj textsträng: <input name="textStr" type="text" /><br />
<input type="submit" value="HIT IT!" />
</form>
<%
If Request.Querystring("do") = "CreateThatCoolTextFile" Then
Const Filename = "/testfilen.txt" ' File to read
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
' Create a filesystem object
Dim FSO
set FSO = server.createObject("Scripting.FileSystemObject")
Dim Filepath
Filepath = Server.MapPath(Filename)
if FSO.FileExists(Filepath) Then
Dim file
set file = FSO.GetFile(Filepath)
Dim FileSize
FileSize = file.Size
' Open the file
Dim TextStream
Set TextStream = file.OpenAsTextStream(ForReading, TristateUseDefault)
' Read the file line by line
Do While Not TextStream.AtEndOfStream
dim Line
Line = TextStream.readline
if not Instr(Line,"CHRYSLER") then response.Write Line & vbcrlf
Loop
Set TextStream = nothing
End If
Set FSO = nothing
End If
%>
<form name="do" method="post" action="tabort.asp?do=CreateThatCoolTextFile">
Välj textsträng: <input name="textStr" type="text" /><br />
<input type="submit" value="HIT IT!" />
</form>
<p style="font-size:10px;">
<%
If Request.Querystring("do") = "CreateThatCoolTextFile" AND NOT Request.Form("textStr") = "" Then
Const Filename = "testfilen.txt" ' File to read
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
' Create a filesystem object
Dim FSO
set FSO = Server.CreateObject("Scripting.FileSystemObject")
Dim Filepath
Filepath = Server.MapPath(Filename)
Response.Write FilePath + "<br />"
if FSO.FileExists(Filepath) Then
Dim file
set file = FSO.GetFile(Filepath)
Dim FileSize
FileSize = file.Size
' Open the file
Dim TextStream
Set TextStream = file.OpenAsTextStream(ForReading, TristateUseDefault)
' Read the file line by line
Do While Not TextStream.AtEndOfStream
dim Line
Line = TextStream.ReadLine
If not Instr(Line,""&Request.Form("textStr")&"") then response.Write Line & vbcrlf else response.write ">>" & Line & vbcrlf
Response.Write("<br />")
Loop
Set TextStream = nothing
End If
Set FSO = nothing
Response.Write("Textfilen är rensad på rader som innehåller """&Request.Form("textStr")&""".")
Else
Response.Write("Knas!")
End If
%>
</p>
<%
set objfso = server.createobject("scripting.filesystemobject")
set objFile = objFso.getFile(server.mappath("testfilen.txt"))
Set textStream = objfso.OpenTextFile(server.mappath("testfilen.txt"),1, False)
arrRows = split(textStream.ReadAll , vbCrLf)
textStream.close
function getText(arrRows,ord)
for i = lbound(arrRows) to ubound(arrRows)
if instr(ArrRows(i),ord) then str = str & "" else str = str & ArrRows(i)
if cint(ubound(arrRows)-1) <> cint(i) then str = str & vbCrLf
next
getText = trim(str)
end function
'Skriv ut text filen men inte där raden med pelle
response.write getText(arrRows,"pelle")
%>
Nu skriver den bara ut dom raderna som inte innehåller ordet som man specificerat.
Kollar man källkoden för sidan då så är de rader som är "borttagna" bara blanka rader.. kan man få dom blanka raderna att försvinna? Och hur gör man för att få detta direkt till textfilen?
if instr(ArrRows(i),ord) then str = str & "" else str = str & ArrRows(i)
if cint(ubound(arrRows)-1) <> cint(i) AND NOT instr(ArrRows(i),ord) then str = str & vbCrLf