Forum Moderators: open
Illegal assignment: 'strPathInfo'
/mainpage_edit.asp, line 43
Here is the code for line 43 etc.:
39. <DIV style="width:600;">
40. <FONT FACE="Arial" SIZE="2" COLOR="#000000">
41.
42. <!-- #INCLUDE file="global.asp" -->
43. <%
44. strPathInfo =("data/mynext.txt") ' root path to text file
45. strPhysicalPath = Server.MapPath(strPathInfo) ' full file path to text file
46.
47. if getTrueFalse(request("callback")) then ' form submitted change file
48. theNewFile = Request.form("theNewFile")
49. fName = Server.MapPath(strPathInfo)
etc..
When I submit and save to the text file, it almost always works, however there are a few times where I wil hit the browser back botton and then reuturn to the website admin page, hit refresh, and then re-go to this page where I edit the text file and sometimes it will give me the error above when I try to save... Any comments, answers, thoughts are greatly apreciated. Thanks.
~Isaac~
Although this code is legal:
strPathInfo =("data/mynext.txt") ' root path to text file
strPhysicalPath = Server.MapPath(strPathInfo) ' full file path to text file
You'd get this error if you were attempting to redefine a Const.
Check global.asp for an assignment of strPathInfo.
<%
' common functions and variables are kept in here
'
'____________ Common functions __________________
' simple debug function
Function dump(strString)
Response.Write("Debug : " & strString & "")
End Function
' function to get true or false boolean values passed from a string
function getTrueFalse(strBoolean)
output=false
if ucase(trim(strBoolean)) = "TRUE" then output= true
getTrueFalse= output
end function
%>
and here is the full script:
<!-- #INCLUDE file="global.asp" -->
<%
strPathInfo = ("mytextfile.txt") ' root path to text file
strPhysicalPath = Server.MapPath(strPathInfo) ' full file path to text file
if getTrueFalse(request("callback")) then ' form submitted change file
theNewFile = Request.form("theNewFile")
fName = Server.MapPath(strPathInfo)
Set objFSO = CreateObject("Scripting.FileSystemObject") ' new filesystemobject
Set objText = objFSO.CreateTextFile(fName, true) ' create new text file with the same name
objText.Write(theNewFile) 'write contents of textarea to new file
objText.Close ' done
updatetext = "File has been saved!<br><br>"
updatetext = updatetext &"<a href="""& request.ServerVariables("SCRIPT_NAME")&""">click here to edit again</a>"
else
' load the file
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
'create filesystemobject (FSO)
set objFSO = CreateObject("Scripting.FileSystemObject")
set objFile = objFSO.GetFile(strPhysicalPath)
textFile = "" ' this will hold the contents of the text file
'open file with FSO
set objFileTextStream = objFile.OpenAsTextStream(ForReading, TristateUseDefault)
Do While objFileTextStream.AtEndOfStream <> True
strFileLine = objFileTextStream.Readline
strLine = Server.HTMLEncode(strFileLine)
strLine = Replace(strLine,CHR(9)," ")
textFile = textFile & strLine & vbCrLf
Loop
objFileTextStream.Close
end if
%>
<!-- #INCLUDE file="global.asp" -->
<CENTER>
<%
if updatetext <> "" then
response.write updatetext
else ' write form
%>
<B>EDIT PAGE</B><BR>
You can edit the text on the page below.<BR>
You can type HTML functions, such as:
BR>
<form action="<%=request.ServerVariables("/asp/editText/Copy%20of%20editText/SCRIPT_NAME")%>" method="post">
<input type="hidden" name="callback" value="true">
<textarea name="theNewFile" cols="70" rows="20" class="field"><%=textFile%></textarea>
<BR>
<input name="Submit" type="submit" class="button" value="Save & Update">
</form>
<%
end if
%>
</CENTER>
3 other items I noticed:
1) Looking over your Full Script I noticed that you're including the same include file twice, not sure if you meant to do that:
On line 1
<!-- #INCLUDE file="global.asp" -->
This appears just before the <center> tag again:
<!-- #INCLUDE file="global.asp" -->
2) The path to the text file in your first post is different that the path in your last post.
3) The Form Post Code looks goofed, I don't see how this form will post to anypage other then itself because this code outputs action="":
action="<%=request.ServerVariables("/asp/editText/Copy%20of%20editText/SCRIPT_NAME")%>"
should be
action="/asp/editText/Copy%20of%20editText<%= Request.ServerVariables("script_name")%>"
~Isaac Lloyd~