|
 |
proasp_howto thread: Scripting Runtime
Message #1 by "Phil Perks" <philp@w...> on Wed, 9 Aug 2000 17:1:46
|
|
----Original Message-----
From: Loh, Kelvin L A G [mailto:klaglo@e...]
Sent: 13 July 2000 15:52
To:
Subject: Scripting Runtime
I had purchase Pro ASP 3 from your company and had problems try to
this section of your code. Could you tell me whats wrong with the code
below? It doesn't seem to respond to any of the 3 buttons provided.
<%@LANGUAGE="VBScript"%>
<HTML>
<HEAD>
<TITLE>The Scripting.TextStream Object</TITLE>
<STYLE TYPE="text/css">
BODY {font-family:Tahoma,Arial,sans-serif; font-size:10pt}
.heading {font-family:Tahoma,Arial,sans-serif; font-size:14pt;
font-weight:bold}
.cite {font-family:Tahoma,Arial,sans-serif; font-size:8pt}
</STYLE>
<!-- METADATA TYPE="typelib" FILE="c:\WinNT\System32\scrrun.dll" -->
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<SPAN CLASS="heading">The Scripting.TextStream Object</SPAN><HR>
<!--------------------------------------------------------------------------
->
<%
strTextFile = Server.MapPath("MyFile.txt")
'create an instance of a FileSytemObject object
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
'look for a command sent from the FORM section buttons
If Len(Request.Form("cmdUpdate")) Then
'write out contents of TEXTAREA to file
strNewText = Request.Form("txtContent")
arrLines = Split(strNewText, vbCrLf)
Set objTStream = objFSO.OpenTextFile(strTextFile, ForWriting, True)
For intLine = 0 To UBound(arrLines)
strThisLine = arrLines(intLine)
If Len(strThisLine) > 4 Then objTStream.WriteLine Mid(strThisLine, 6)
Next
objTStream.Close
End If
If Len(Request.Form("cmdAppend")) Then
'append contents of TEXTAREA to file
strNewText = Request.Form("txtContent")
arrLines = Split(strNewText, vbCrLf)
Set objTStream = objFSO.OpenTextFile(strTextFile, ForAppending)
For intLine = 0 To UBound(arrLines)
strThisLine = arrLines(intLine)
If Len(strThisLine) > 4 Then objTStream.WriteLine Mid(strThisLine, 6)
Next
objTStream.Close
End If
If Len(Request.Form("cmdDefault")) Then
'write out default contents to file
Set objTStream = objFSO.CreateTextFile(strTextFile, True, False)
objTStream.WriteLine "At last I can create files with VBScript!"
objTStream.WriteLine
objTStream.WriteLine "Here are three blank lines:"
objTStream.WriteBlankLines 3
objTStream.Write "... and this is "
objTStream.WriteLine "the last line."
objTStream.Close
End If
%>
<!-- collect values to execute TextStream methods with -->
<FORM ACTION="<% = Request.ServerVariables("SCRIPT_NAME") %>"
METHOD="POST">
The contents of the disk file <B><% = strTextFile %></B> are:<P>
<TEXTAREA NAME="txtContent" ROWS="10" COLS="50" WRAP="PHYSICAL">
</TEXTAREA><P>
<%
'open the text file as a TextStream object
Set objTStream = objFSO.OpenTextFile(strTextFile, ForReading)
'read one line at a time until the end of the file is reached
objTStream.Close
%>
<INPUT TYPE="SUBMIT" NAME="cmdUpdate" VALUE=" ">
<B>Update</B> the text file with my changes above<BR>
<INPUT TYPE="SUBMIT" NAME="cmdAppend" VALUE=" ">
<B>Append</B> my text to the existing text file contents<BR>
<INPUT TYPE="SUBMIT" NAME="cmdDefault" VALUE=" ">
<B>Restore</B> the default contents of the text file<BR>
</FORM>
<!--------------------------------------------------------------------------
->
<HR>
</BODY>
</HTML>
Could you please assist me? Thank you.
Sincerely
Kelvin
|
|
 |