请问这样错在那里 指点我下 谢谢

来源:百度知道 编辑:UC知道 时间:2024/07/01 01:35:58
<!--#include file="CONN.ASP"-->
<%'打开模板代码
Dim fso,htmlwrite
Dim qq,qqw,strOut
Set htmlwrite=fso.OpenTextFile(Server.MapPath("Template.htm"))
strOut=f.ReadAll
htmlwrite.close

for v=4 to 9
sql="select Name,ziliao from wenzhang where id="&v&""
set rs1=Server.CreateObject("adodb.recordset")
rs1.open sql,connstr,2,3

qq=rs1("Name")
qqw=rs1("ziliao")

strOut==replace(strOut,"$qq$",qq)
strOut==replace(strOut,"$qqw$",qqw)
filepath=v&".shtml"
rs1.close
set rs1=nothing

'生成HTML页面
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set fout = fso.CreateTextFile(Server.MapPath(filepath))
fout.WriteLine strOut
fout.close
next
%>

我只发现了一处错误:

第一段代码:

strOut=f.ReadAll

这里的f是什么,是htmlwrite吗?

最后一段代码里面的

Set fso = Server.CreateObject("Scripting.FileSystemObject")

这个语句不应该写在for循环里面,没有必要。

所以这个程序可以这样写:

<!--#include file="CONN.ASP"-->
<%'打开模板代码
Dim fso,htmlwrite
Dim qq,qqw,strOut
Set htmlwrite=fso.OpenTextFile(Server.MapPath("Template.htm"))
strOut=htmlwrite.ReadAll
htmlwrite.close

Set fso = Server.CreateObject("Scripting.FileSystemObject")
'定义fso对象,写一次就可以了。

for v=4 to 9
sql="select Name,ziliao from wenzhang where id="&v&""
set rs1=Server.CreateObject("adodb.recordset")
rs1.open sql,connstr,2,3

qq=rs1("Name")
qqw=rs1("ziliao")

strOut==replace(strOut,"$qq$",qq)
strOut==replace(strOut,"$qqw$",qq