<form method="post" action="wd_yj_upload.asp" name="uploadform" enctype="multipart/form-data" onsubmit="return mysubmit();" >
<ul id="file_group">
<li>文件编号:<%=request.querystring("wdbh")%>
<li>文件名称:<%=request.querystring("wd_name")%>
<li>上传扫描件:<input name="mfile1" type="file" style="WIDTH:70%" />
<li>扫描件名称:<input name="img_name_1" type="text" id="img_name_1" style="WIDTH:57%"> 页码标记:<input name="ym" type="text" id="ym" style="WIDTH:5%" value="<%=totalPut%>" >
<li/><input type="submit" value="上传文件" /><input type="button" value="放弃返回" onClick="window.history.go(-1)">
<input name="flbh" type="hidden" id="flbh" value="<%=request.querystring("flbh")%>" />
<input name="fl_name" type="hidden" id="fl_name" value="<%=request.querystring("fl_name")%>" />
<input name="wdbh" type="hidden" id="wdbh" value="<%=request.querystring("wdbh")%>" />
<input name="wd_name" type="hidden" id="wd_name" value="<%=request.querystring("wd_name")%>" />
</ul>
</FORM>
在upload_5xsoft.inc
Microsoft VBScript 运行时错误 '800a005e'
无效使用 Null
\wdxt\upload_5xsoft.inc, line 44
就是这句话代码
sStart = MidB(RequestData,1, InStrB(iFormStart,RequestData,vbCrlf)-1)
希望朋友们指点~~~
10 个解决方案
#1
有人能帮帮吗?
#2
sStart = MidB(RequestData,1, InStrB(iFormStart,RequestData,vbCrlf)-1)
上一句及下一句是什么? 或这把这一块都贴出来
上一句及下一句是什么? 或这把这一块都贴出来
#3
给个您参考, 百度搜索的:
自己用ACCESS做的一个出卷系统的代码,在查看试卷这部分的代码出现了无效使用NULL 错误 不知道怎么改,高手指导一下。
代码如下:Private Sub cmdSave_Click()
Dim fso As New FileSystemObject, fil As TextStream
CommonDialog1.DialogTitle = "选择试卷文件路径/指定文件名"
CommonDialog1.Filter = "试卷文件(*.txt)|*.txt"
CommonDialog1.FileName = Application.CurrentProject.Path & "\我的试卷.txt"
Do
CommonDialog1.ShowSave
If fso.FileExists(CommonDialog1.FileName) Then
n = MsgBox(CommonDialog1.FileName & vbCrLf _
& "已存在,是否覆盖该文件?", vbCritical + vbYesNo)
If n = vbYes Then Exit Do
Else
Exit Do
End If
Loop
'将生成的试卷和答案写入文件
Set fil = fso.CreateTextFile(CommonDialog1.FileName)
fil.WriteLine txtTest
fil.Close
MsgBox "试卷已成功保存到<" & CommonDialog1.FileName _
& ">中!", vbInformation
isSaved = True
End Sub
这一句出的错误: fil.WriteLine txtTest
------------------------
自己用ACCESS做的一个出卷系统的代码,在查看试卷这部分的代码出现了无效使用NULL 错误 不知道怎么改,高手指导一下。
代码如下:Private Sub cmdSave_Click()
Dim fso As New FileSystemObject, fil As TextStream
CommonDialog1.DialogTitle = "选择试卷文件路径/指定文件名"
CommonDialog1.Filter = "试卷文件(*.txt)|*.txt"
CommonDialog1.FileName = Application.CurrentProject.Path & "\我的试卷.txt"
Do
CommonDialog1.ShowSave
If fso.FileExists(CommonDialog1.FileName) Then
n = MsgBox(CommonDialog1.FileName & vbCrLf _
& "已存在,是否覆盖该文件?", vbCritical + vbYesNo)
If n = vbYes Then Exit Do
Else
Exit Do
End If
Loop
'将生成的试卷和答案写入文件
Set fil = fso.CreateTextFile(CommonDialog1.FileName)
fil.WriteLine txtTest
fil.Close
MsgBox "试卷已成功保存到<" & CommonDialog1.FileName _
& ">中!", vbInformation
isSaved = True
End Sub
这一句出的错误: fil.WriteLine txtTest
------------------------
Private Sub cmdSave_Click()
Dim fso As New FileSystemObject, fil As TextStream
CommonDialog1.DialogTitle = "选择试卷文件路径/指定文件名"
CommonDialog1.Filter = "试卷文件(*.txt)|*.txt"
CommonDialog1.FileName = Application.CurrentProject.Path & "\我的试卷.txt"
Do
CommonDialog1.ShowSave
If fso.FileExists(CommonDialog1.FileName) Then
n = MsgBox(CommonDialog1.FileName & vbCrLf _
& "已存在,是否覆盖该文件?", vbCritical + vbYesNo)
If n = vbYes Then Exit Do
Else
Exit Do
End If
Loop
'将生成的试卷和答案写入文件
Set fil = fso.CreateTextFile(CommonDialog1.FileName)
if isnull(txtTest )=true then
msgbox "现在 txtTest 是NULL值,无法继续执行!"
else
fil.WriteLine txtTest
fil.Close
MsgBox "试卷已成功保存到<" & CommonDialog1.FileName _
& ">中!", vbInformation
isSaved = True
end if
End Sub
#4
InStrB(iFormStart,RequestData,vbCrlf) 这个 可能返回了Null
没有在 RequestData里从iFormStart开始的位置找到vbCrlf
没有在 RequestData里从iFormStart开始的位置找到vbCrlf
#5
wd_yj_upload.asp代码
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936" %>
<%OPTION EXPLICIT%>
<%Server.ScriptTimeOut=5000%>
<!-- #include file="conn.asp" -->
<!--#include file="upload_5xsoft.inc"-->
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=gb2312" />
<title>文件上传</title>
</head>
<body>
<br>文件上传成功!<hr size=1 noshadow width=300 align=left><br>
<%
'Response.Charset="gb2312"
dim upload,file,formName,uploadPath,iCount,fname,fl_name,wdbh,wd_name,rs_wd_yj,sql_wd_yj,ym,totalPut,wdsm,sql_1,img_name_1,MakeFileName
set fl_name=request.form("fl_name")
set wdbh=request.form("wdbh")
set wd_name=request.form("wd_name")
set img_name_1=request.form("img_name_1")
set ym=request.form("ym")
set upload=new upload_5xsoft
'--------------将记录写入数据库(起)---------------------------------------
sql_1 = "insert into wd_yj (wdbh,wd_name,img_name,img_name_1,wdsm) values ('"&wdbh&"','"&wd_name&"','"&MakeFileName&"','"&img_name_1&"','"&wdsm&"')"
conn.execute(sql_1) '执行SQL新增
'--------------将记录写入数据库(起)---------------------------------------
uploadPath="../data/wdxt/wdwj/"&fl_name&"/"
iCount=0
for each formName in upload.objFile
set file=upload.file(formName)
if file.FileSize>0 then
fname=upload.MakeFileName(file.FileExt)
file.SaveAs Server.mappath(uploadPath & fname)
iCount=iCount+1
end if
set file=nothing
next
set upload=nothing
response.write "<br>"&formName
response.write "<br>" & iCount & " 个文件上传结束![<a href=""javascript:history.back();"">返回</a>]"
%>
</body>
<%
conn.close
set conn = nothing
%>
</html>
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936" %>
<%OPTION EXPLICIT%>
<%Server.ScriptTimeOut=5000%>
<!-- #include file="conn.asp" -->
<!--#include file="upload_5xsoft.inc"-->
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=gb2312" />
<title>文件上传</title>
</head>
<body>
<br>文件上传成功!<hr size=1 noshadow width=300 align=left><br>
<%
'Response.Charset="gb2312"
dim upload,file,formName,uploadPath,iCount,fname,fl_name,wdbh,wd_name,rs_wd_yj,sql_wd_yj,ym,totalPut,wdsm,sql_1,img_name_1,MakeFileName
set fl_name=request.form("fl_name")
set wdbh=request.form("wdbh")
set wd_name=request.form("wd_name")
set img_name_1=request.form("img_name_1")
set ym=request.form("ym")
set upload=new upload_5xsoft
'--------------将记录写入数据库(起)---------------------------------------
sql_1 = "insert into wd_yj (wdbh,wd_name,img_name,img_name_1,wdsm) values ('"&wdbh&"','"&wd_name&"','"&MakeFileName&"','"&img_name_1&"','"&wdsm&"')"
conn.execute(sql_1) '执行SQL新增
'--------------将记录写入数据库(起)---------------------------------------
uploadPath="../data/wdxt/wdwj/"&fl_name&"/"
iCount=0
for each formName in upload.objFile
set file=upload.file(formName)
if file.FileSize>0 then
fname=upload.MakeFileName(file.FileExt)
file.SaveAs Server.mappath(uploadPath & fname)
iCount=iCount+1
end if
set file=nothing
next
set upload=nothing
response.write "<br>"&formName
response.write "<br>" & iCount & " 个文件上传结束![<a href=""javascript:history.back();"">返回</a>]"
%>
</body>
<%
conn.close
set conn = nothing
%>
</html>
#6
upload_5xsoft.inc代码
<%
dim Data_5xsoft
Class upload_5xsoft
dim objForm,objFile,Version
Public function Form(strForm)
strForm=lcase(strForm)
if not objForm.exists(strForm) then
Form=""
else
Form=objForm(strForm)
end if
end function
Public function File(strFile)
strFile=lcase(strFile)
if not objFile.exists(strFile) then
set File=new FileInfo
else
set File=objFile(strFile)
end if
end function
Private Sub Class_Initialize
dim RequestData,sStart,vbCrlf,sInfo,iInfoStart,iInfoEnd,tStream,iStart,theFile
dim iFileSize,sFilePath,sFileType,sFormValue,sFileName
dim iFindStart,iFindEnd
dim iFormStart,iFormEnd,sFormName
Version="化境HTTP上传程序 Version 2.1"
set objForm=Server.CreateObject("Scripting.Dictionary")
set objFile=Server.CreateObject("Scripting.Dictionary")
if Request.TotalBytes<1 then Exit Sub
set tStream = Server.CreateObject("adodb.stream")
set Data_5xsoft = Server.CreateObject("adodb.stream")
Data_5xsoft.Type = 1
Data_5xsoft.Mode =3
Data_5xsoft.Open
Data_5xsoft.Write Request.BinaryRead(Request.TotalBytes)
Data_5xsoft.Position=0
RequestData =Data_5xsoft.Read
iFormStart = 1
iFormEnd = LenB(RequestData)
vbCrlf = chrB(13) & chrB(10)
sStart = MidB(RequestData,1, InStrB(iFormStart,RequestData,vbCrlf)-1)
iStart = LenB (sStart)
iFormStart=iFormStart+iStart+1
while (iFormStart + 10) < iFormEnd
iInfoEnd = InStrB(iFormStart,RequestData,vbCrlf & vbCrlf)+3
tStream.Type = 1
tStream.Mode =3
tStream.Open
Data_5xsoft.Position = iFormStart
Data_5xsoft.CopyTo tStream,iInfoEnd-iFormStart
tStream.Position = 0
tStream.Type = 2
tStream.Charset ="gb2312"
sInfo = tStream.ReadText
tStream.Close
'取得表单项目名称
iFormStart = InStrB(iInfoEnd,RequestData,sStart)
iFindStart = InStr(22,sInfo,"name=""",1)+6
iFindEnd = InStr(iFindStart,sInfo,"""",1)
sFormName = lcase(Mid (sinfo,iFindStart,iFindEnd-iFindStart))
'如果是文件
if InStr (45,sInfo,"filename=""",1) > 0 then
set theFile=new FileInfo
'取得文件名
iFindStart = InStr(iFindEnd,sInfo,"filename=""",1)+10
iFindEnd = InStr(iFindStart,sInfo,"""",1)
sFileName = Mid (sinfo,iFindStart,iFindEnd-iFindStart)
theFile.FileName=getFileName(sFileName)
theFile.FilePath=getFilePath(sFileName)
theFile.FileExt=GetFileExt(sFileName)
'取得文件类型
iFindStart = InStr(iFindEnd,sInfo,"Content-Type: ",1)+14
iFindEnd = InStr(iFindStart,sInfo,vbCr)
theFile.FileType =Mid (sinfo,iFindStart,iFindEnd-iFindStart)
theFile.FileStart =iInfoEnd
theFile.FileSize = iFormStart -iInfoEnd -3
theFile.FormName=sFormName
if not objFile.Exists(sFormName) then
objFile.add sFormName,theFile
end if
else
'如果是表单项目
tStream.Type =1
tStream.Mode =3
tStream.Open
Data_5xsoft.Position = iInfoEnd
Data_5xsoft.CopyTo tStream,iFormStart-iInfoEnd-3
tStream.Position = 0
tStream.Type = 2
tStream.Charset ="gb2312"
sFormValue = tStream.ReadText
tStream.Close
if objForm.Exists(sFormName) then
objForm(sFormName)=objForm(sFormName)&", "&sFormValue
else
objForm.Add sFormName,sFormValue
end if
end if
iFormStart=iFormStart+iStart+1
wend
RequestData=""
set tStream =nothing
End Sub
Private Sub Class_Terminate
if Request.TotalBytes>0 then
objForm.RemoveAll
objFile.RemoveAll
set objForm=nothing
set objFile=nothing
Data_5xsoft.Close
set Data_5xsoft =nothing
end if
End Sub
Private function GetFilePath(FullPath)
If FullPath <> "" Then
GetFilePath = left(FullPath,InStrRev(FullPath, "\"))
Else
GetFilePath = ""
End If
End function
Private function GetFileExt(FullPath)
If FullPath <> "" Then
GetFileExt = mid(FullPath,InStrRev(FullPath, ".")+1)
Else
GetFileExt = ""
End If
End function
Private function GetFileName(FullPath)
If FullPath <> "" Then
GetFileName = mid(FullPath,InStrRev(FullPath, "\")+1)
Else
GetFileName = ""
End If
End function
Public Function MakeFileName(Ext)
If Ext<>"" Then
'''Dim DateYear,DateMonth,DateDay,DateHour,DateMinute,DateSecond,FileRnd
'''DateYear=Year(Now())
'''DateMonth=Month(Now())
'''DateDay=Day(Now())
'''DateHour=Hour(Now())
'''DateMinute=Minute(Now())
'''DateSecond=Second(Now())
'''If Len(DateMonth)<2 Then DateMonth="0" & DateMonth
'''If Len(DateDay)<2 Then DateDay="0" & DateDay
'''If Len(DateHour)<2 Then DateHour="0" & DateHour
'''If Len(DateMinute)<2 Then DateMinute="0" & DateMinute
'''If Len(DateSecond)<2 Then DateSecond="0" & DateSecond
'''Randomize
'''FileRnd=CStr(Int(Rnd()*1000))
'''If Len(FileRnd)=2 Then FileRnd="0" & FileRnd
'''If Len(FileRnd)=1 Then FileRnd="00" & FileRnd
'''MakeFileName=DateYear & DateMonth & DateDay & DateHour & DateMinute & DateSecond & FileRnd & "." & Ext
MakeFileName= wd_name &"_"&ym&"." & Ext
End If
End Function
End Class
Class FileInfo
dim FormName,FileName,FilePath,FileSize,FileExt,FileType,FileStart
Private Sub Class_Initialize
FileName = ""
FilePath = ""
FileSize = 0
FileStart= 0
FormName = ""
FileType = ""
FileExt = ""
End Sub
Public function SaveAs(FullPath)
dim dr,ErrorChar,i
SaveAs=true
if trim(fullpath)="" or FileStart=0 or FileName="" or right(fullpath,1)="/" then exit function
set dr=CreateObject("Adodb.Stream")
dr.Mode=3
dr.Type=1
dr.Open
Data_5xsoft.position=FileStart
Data_5xsoft.copyto dr,FileSize
dr.SaveToFile FullPath,2
dr.Close
set dr=nothing
SaveAs=false
end function
End Class
%>
还是把全部代码贴上了
对upload_5xsoft.inc这个文件不了解!
<%
dim Data_5xsoft
Class upload_5xsoft
dim objForm,objFile,Version
Public function Form(strForm)
strForm=lcase(strForm)
if not objForm.exists(strForm) then
Form=""
else
Form=objForm(strForm)
end if
end function
Public function File(strFile)
strFile=lcase(strFile)
if not objFile.exists(strFile) then
set File=new FileInfo
else
set File=objFile(strFile)
end if
end function
Private Sub Class_Initialize
dim RequestData,sStart,vbCrlf,sInfo,iInfoStart,iInfoEnd,tStream,iStart,theFile
dim iFileSize,sFilePath,sFileType,sFormValue,sFileName
dim iFindStart,iFindEnd
dim iFormStart,iFormEnd,sFormName
Version="化境HTTP上传程序 Version 2.1"
set objForm=Server.CreateObject("Scripting.Dictionary")
set objFile=Server.CreateObject("Scripting.Dictionary")
if Request.TotalBytes<1 then Exit Sub
set tStream = Server.CreateObject("adodb.stream")
set Data_5xsoft = Server.CreateObject("adodb.stream")
Data_5xsoft.Type = 1
Data_5xsoft.Mode =3
Data_5xsoft.Open
Data_5xsoft.Write Request.BinaryRead(Request.TotalBytes)
Data_5xsoft.Position=0
RequestData =Data_5xsoft.Read
iFormStart = 1
iFormEnd = LenB(RequestData)
vbCrlf = chrB(13) & chrB(10)
sStart = MidB(RequestData,1, InStrB(iFormStart,RequestData,vbCrlf)-1)
iStart = LenB (sStart)
iFormStart=iFormStart+iStart+1
while (iFormStart + 10) < iFormEnd
iInfoEnd = InStrB(iFormStart,RequestData,vbCrlf & vbCrlf)+3
tStream.Type = 1
tStream.Mode =3
tStream.Open
Data_5xsoft.Position = iFormStart
Data_5xsoft.CopyTo tStream,iInfoEnd-iFormStart
tStream.Position = 0
tStream.Type = 2
tStream.Charset ="gb2312"
sInfo = tStream.ReadText
tStream.Close
'取得表单项目名称
iFormStart = InStrB(iInfoEnd,RequestData,sStart)
iFindStart = InStr(22,sInfo,"name=""",1)+6
iFindEnd = InStr(iFindStart,sInfo,"""",1)
sFormName = lcase(Mid (sinfo,iFindStart,iFindEnd-iFindStart))
'如果是文件
if InStr (45,sInfo,"filename=""",1) > 0 then
set theFile=new FileInfo
'取得文件名
iFindStart = InStr(iFindEnd,sInfo,"filename=""",1)+10
iFindEnd = InStr(iFindStart,sInfo,"""",1)
sFileName = Mid (sinfo,iFindStart,iFindEnd-iFindStart)
theFile.FileName=getFileName(sFileName)
theFile.FilePath=getFilePath(sFileName)
theFile.FileExt=GetFileExt(sFileName)
'取得文件类型
iFindStart = InStr(iFindEnd,sInfo,"Content-Type: ",1)+14
iFindEnd = InStr(iFindStart,sInfo,vbCr)
theFile.FileType =Mid (sinfo,iFindStart,iFindEnd-iFindStart)
theFile.FileStart =iInfoEnd
theFile.FileSize = iFormStart -iInfoEnd -3
theFile.FormName=sFormName
if not objFile.Exists(sFormName) then
objFile.add sFormName,theFile
end if
else
'如果是表单项目
tStream.Type =1
tStream.Mode =3
tStream.Open
Data_5xsoft.Position = iInfoEnd
Data_5xsoft.CopyTo tStream,iFormStart-iInfoEnd-3
tStream.Position = 0
tStream.Type = 2
tStream.Charset ="gb2312"
sFormValue = tStream.ReadText
tStream.Close
if objForm.Exists(sFormName) then
objForm(sFormName)=objForm(sFormName)&", "&sFormValue
else
objForm.Add sFormName,sFormValue
end if
end if
iFormStart=iFormStart+iStart+1
wend
RequestData=""
set tStream =nothing
End Sub
Private Sub Class_Terminate
if Request.TotalBytes>0 then
objForm.RemoveAll
objFile.RemoveAll
set objForm=nothing
set objFile=nothing
Data_5xsoft.Close
set Data_5xsoft =nothing
end if
End Sub
Private function GetFilePath(FullPath)
If FullPath <> "" Then
GetFilePath = left(FullPath,InStrRev(FullPath, "\"))
Else
GetFilePath = ""
End If
End function
Private function GetFileExt(FullPath)
If FullPath <> "" Then
GetFileExt = mid(FullPath,InStrRev(FullPath, ".")+1)
Else
GetFileExt = ""
End If
End function
Private function GetFileName(FullPath)
If FullPath <> "" Then
GetFileName = mid(FullPath,InStrRev(FullPath, "\")+1)
Else
GetFileName = ""
End If
End function
Public Function MakeFileName(Ext)
If Ext<>"" Then
'''Dim DateYear,DateMonth,DateDay,DateHour,DateMinute,DateSecond,FileRnd
'''DateYear=Year(Now())
'''DateMonth=Month(Now())
'''DateDay=Day(Now())
'''DateHour=Hour(Now())
'''DateMinute=Minute(Now())
'''DateSecond=Second(Now())
'''If Len(DateMonth)<2 Then DateMonth="0" & DateMonth
'''If Len(DateDay)<2 Then DateDay="0" & DateDay
'''If Len(DateHour)<2 Then DateHour="0" & DateHour
'''If Len(DateMinute)<2 Then DateMinute="0" & DateMinute
'''If Len(DateSecond)<2 Then DateSecond="0" & DateSecond
'''Randomize
'''FileRnd=CStr(Int(Rnd()*1000))
'''If Len(FileRnd)=2 Then FileRnd="0" & FileRnd
'''If Len(FileRnd)=1 Then FileRnd="00" & FileRnd
'''MakeFileName=DateYear & DateMonth & DateDay & DateHour & DateMinute & DateSecond & FileRnd & "." & Ext
MakeFileName= wd_name &"_"&ym&"." & Ext
End If
End Function
End Class
Class FileInfo
dim FormName,FileName,FilePath,FileSize,FileExt,FileType,FileStart
Private Sub Class_Initialize
FileName = ""
FilePath = ""
FileSize = 0
FileStart= 0
FormName = ""
FileType = ""
FileExt = ""
End Sub
Public function SaveAs(FullPath)
dim dr,ErrorChar,i
SaveAs=true
if trim(fullpath)="" or FileStart=0 or FileName="" or right(fullpath,1)="/" then exit function
set dr=CreateObject("Adodb.Stream")
dr.Mode=3
dr.Type=1
dr.Open
Data_5xsoft.position=FileStart
Data_5xsoft.copyto dr,FileSize
dr.SaveToFile FullPath,2
dr.Close
set dr=nothing
SaveAs=false
end function
End Class
%>
还是把全部代码贴上了
对upload_5xsoft.inc这个文件不了解!
#7
有人能帮帮吗?
#8
不能用 request.form 取值的,用了之后 upload_5xsoft 就取不到值了
要全部用 upload_5xsoft 取值
对象赋值用set, 一般变量赋值不需要Set
set upload = new upload_5xsoft
fl_name = upload.form("fl_name")
wdbh = upload.form("wdbh")
wd_name = upload.form("wd_name")
img_name_1 = upload.form("img_name_1")
ym = upload.form("ym")
要全部用 upload_5xsoft 取值
对象赋值用set, 一般变量赋值不需要Set
set upload = new upload_5xsoft
fl_name = upload.form("fl_name")
wdbh = upload.form("wdbh")
wd_name = upload.form("wd_name")
img_name_1 = upload.form("img_name_1")
ym = upload.form("ym")
#9
今天也遇到这个问题,www.fs526.com这个网站,
#10
这个问题嘛,不好说啊,你可以去这个站上看看,比较全www.bycxlw.com
#1
有人能帮帮吗?
#2
sStart = MidB(RequestData,1, InStrB(iFormStart,RequestData,vbCrlf)-1)
上一句及下一句是什么? 或这把这一块都贴出来
上一句及下一句是什么? 或这把这一块都贴出来
#3
给个您参考, 百度搜索的:
自己用ACCESS做的一个出卷系统的代码,在查看试卷这部分的代码出现了无效使用NULL 错误 不知道怎么改,高手指导一下。
代码如下:Private Sub cmdSave_Click()
Dim fso As New FileSystemObject, fil As TextStream
CommonDialog1.DialogTitle = "选择试卷文件路径/指定文件名"
CommonDialog1.Filter = "试卷文件(*.txt)|*.txt"
CommonDialog1.FileName = Application.CurrentProject.Path & "\我的试卷.txt"
Do
CommonDialog1.ShowSave
If fso.FileExists(CommonDialog1.FileName) Then
n = MsgBox(CommonDialog1.FileName & vbCrLf _
& "已存在,是否覆盖该文件?", vbCritical + vbYesNo)
If n = vbYes Then Exit Do
Else
Exit Do
End If
Loop
'将生成的试卷和答案写入文件
Set fil = fso.CreateTextFile(CommonDialog1.FileName)
fil.WriteLine txtTest
fil.Close
MsgBox "试卷已成功保存到<" & CommonDialog1.FileName _
& ">中!", vbInformation
isSaved = True
End Sub
这一句出的错误: fil.WriteLine txtTest
------------------------
自己用ACCESS做的一个出卷系统的代码,在查看试卷这部分的代码出现了无效使用NULL 错误 不知道怎么改,高手指导一下。
代码如下:Private Sub cmdSave_Click()
Dim fso As New FileSystemObject, fil As TextStream
CommonDialog1.DialogTitle = "选择试卷文件路径/指定文件名"
CommonDialog1.Filter = "试卷文件(*.txt)|*.txt"
CommonDialog1.FileName = Application.CurrentProject.Path & "\我的试卷.txt"
Do
CommonDialog1.ShowSave
If fso.FileExists(CommonDialog1.FileName) Then
n = MsgBox(CommonDialog1.FileName & vbCrLf _
& "已存在,是否覆盖该文件?", vbCritical + vbYesNo)
If n = vbYes Then Exit Do
Else
Exit Do
End If
Loop
'将生成的试卷和答案写入文件
Set fil = fso.CreateTextFile(CommonDialog1.FileName)
fil.WriteLine txtTest
fil.Close
MsgBox "试卷已成功保存到<" & CommonDialog1.FileName _
& ">中!", vbInformation
isSaved = True
End Sub
这一句出的错误: fil.WriteLine txtTest
------------------------
Private Sub cmdSave_Click()
Dim fso As New FileSystemObject, fil As TextStream
CommonDialog1.DialogTitle = "选择试卷文件路径/指定文件名"
CommonDialog1.Filter = "试卷文件(*.txt)|*.txt"
CommonDialog1.FileName = Application.CurrentProject.Path & "\我的试卷.txt"
Do
CommonDialog1.ShowSave
If fso.FileExists(CommonDialog1.FileName) Then
n = MsgBox(CommonDialog1.FileName & vbCrLf _
& "已存在,是否覆盖该文件?", vbCritical + vbYesNo)
If n = vbYes Then Exit Do
Else
Exit Do
End If
Loop
'将生成的试卷和答案写入文件
Set fil = fso.CreateTextFile(CommonDialog1.FileName)
if isnull(txtTest )=true then
msgbox "现在 txtTest 是NULL值,无法继续执行!"
else
fil.WriteLine txtTest
fil.Close
MsgBox "试卷已成功保存到<" & CommonDialog1.FileName _
& ">中!", vbInformation
isSaved = True
end if
End Sub
#4
InStrB(iFormStart,RequestData,vbCrlf) 这个 可能返回了Null
没有在 RequestData里从iFormStart开始的位置找到vbCrlf
没有在 RequestData里从iFormStart开始的位置找到vbCrlf
#5
wd_yj_upload.asp代码
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936" %>
<%OPTION EXPLICIT%>
<%Server.ScriptTimeOut=5000%>
<!-- #include file="conn.asp" -->
<!--#include file="upload_5xsoft.inc"-->
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=gb2312" />
<title>文件上传</title>
</head>
<body>
<br>文件上传成功!<hr size=1 noshadow width=300 align=left><br>
<%
'Response.Charset="gb2312"
dim upload,file,formName,uploadPath,iCount,fname,fl_name,wdbh,wd_name,rs_wd_yj,sql_wd_yj,ym,totalPut,wdsm,sql_1,img_name_1,MakeFileName
set fl_name=request.form("fl_name")
set wdbh=request.form("wdbh")
set wd_name=request.form("wd_name")
set img_name_1=request.form("img_name_1")
set ym=request.form("ym")
set upload=new upload_5xsoft
'--------------将记录写入数据库(起)---------------------------------------
sql_1 = "insert into wd_yj (wdbh,wd_name,img_name,img_name_1,wdsm) values ('"&wdbh&"','"&wd_name&"','"&MakeFileName&"','"&img_name_1&"','"&wdsm&"')"
conn.execute(sql_1) '执行SQL新增
'--------------将记录写入数据库(起)---------------------------------------
uploadPath="../data/wdxt/wdwj/"&fl_name&"/"
iCount=0
for each formName in upload.objFile
set file=upload.file(formName)
if file.FileSize>0 then
fname=upload.MakeFileName(file.FileExt)
file.SaveAs Server.mappath(uploadPath & fname)
iCount=iCount+1
end if
set file=nothing
next
set upload=nothing
response.write "<br>"&formName
response.write "<br>" & iCount & " 个文件上传结束![<a href=""javascript:history.back();"">返回</a>]"
%>
</body>
<%
conn.close
set conn = nothing
%>
</html>
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936" %>
<%OPTION EXPLICIT%>
<%Server.ScriptTimeOut=5000%>
<!-- #include file="conn.asp" -->
<!--#include file="upload_5xsoft.inc"-->
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=gb2312" />
<title>文件上传</title>
</head>
<body>
<br>文件上传成功!<hr size=1 noshadow width=300 align=left><br>
<%
'Response.Charset="gb2312"
dim upload,file,formName,uploadPath,iCount,fname,fl_name,wdbh,wd_name,rs_wd_yj,sql_wd_yj,ym,totalPut,wdsm,sql_1,img_name_1,MakeFileName
set fl_name=request.form("fl_name")
set wdbh=request.form("wdbh")
set wd_name=request.form("wd_name")
set img_name_1=request.form("img_name_1")
set ym=request.form("ym")
set upload=new upload_5xsoft
'--------------将记录写入数据库(起)---------------------------------------
sql_1 = "insert into wd_yj (wdbh,wd_name,img_name,img_name_1,wdsm) values ('"&wdbh&"','"&wd_name&"','"&MakeFileName&"','"&img_name_1&"','"&wdsm&"')"
conn.execute(sql_1) '执行SQL新增
'--------------将记录写入数据库(起)---------------------------------------
uploadPath="../data/wdxt/wdwj/"&fl_name&"/"
iCount=0
for each formName in upload.objFile
set file=upload.file(formName)
if file.FileSize>0 then
fname=upload.MakeFileName(file.FileExt)
file.SaveAs Server.mappath(uploadPath & fname)
iCount=iCount+1
end if
set file=nothing
next
set upload=nothing
response.write "<br>"&formName
response.write "<br>" & iCount & " 个文件上传结束![<a href=""javascript:history.back();"">返回</a>]"
%>
</body>
<%
conn.close
set conn = nothing
%>
</html>
#6
upload_5xsoft.inc代码
<%
dim Data_5xsoft
Class upload_5xsoft
dim objForm,objFile,Version
Public function Form(strForm)
strForm=lcase(strForm)
if not objForm.exists(strForm) then
Form=""
else
Form=objForm(strForm)
end if
end function
Public function File(strFile)
strFile=lcase(strFile)
if not objFile.exists(strFile) then
set File=new FileInfo
else
set File=objFile(strFile)
end if
end function
Private Sub Class_Initialize
dim RequestData,sStart,vbCrlf,sInfo,iInfoStart,iInfoEnd,tStream,iStart,theFile
dim iFileSize,sFilePath,sFileType,sFormValue,sFileName
dim iFindStart,iFindEnd
dim iFormStart,iFormEnd,sFormName
Version="化境HTTP上传程序 Version 2.1"
set objForm=Server.CreateObject("Scripting.Dictionary")
set objFile=Server.CreateObject("Scripting.Dictionary")
if Request.TotalBytes<1 then Exit Sub
set tStream = Server.CreateObject("adodb.stream")
set Data_5xsoft = Server.CreateObject("adodb.stream")
Data_5xsoft.Type = 1
Data_5xsoft.Mode =3
Data_5xsoft.Open
Data_5xsoft.Write Request.BinaryRead(Request.TotalBytes)
Data_5xsoft.Position=0
RequestData =Data_5xsoft.Read
iFormStart = 1
iFormEnd = LenB(RequestData)
vbCrlf = chrB(13) & chrB(10)
sStart = MidB(RequestData,1, InStrB(iFormStart,RequestData,vbCrlf)-1)
iStart = LenB (sStart)
iFormStart=iFormStart+iStart+1
while (iFormStart + 10) < iFormEnd
iInfoEnd = InStrB(iFormStart,RequestData,vbCrlf & vbCrlf)+3
tStream.Type = 1
tStream.Mode =3
tStream.Open
Data_5xsoft.Position = iFormStart
Data_5xsoft.CopyTo tStream,iInfoEnd-iFormStart
tStream.Position = 0
tStream.Type = 2
tStream.Charset ="gb2312"
sInfo = tStream.ReadText
tStream.Close
'取得表单项目名称
iFormStart = InStrB(iInfoEnd,RequestData,sStart)
iFindStart = InStr(22,sInfo,"name=""",1)+6
iFindEnd = InStr(iFindStart,sInfo,"""",1)
sFormName = lcase(Mid (sinfo,iFindStart,iFindEnd-iFindStart))
'如果是文件
if InStr (45,sInfo,"filename=""",1) > 0 then
set theFile=new FileInfo
'取得文件名
iFindStart = InStr(iFindEnd,sInfo,"filename=""",1)+10
iFindEnd = InStr(iFindStart,sInfo,"""",1)
sFileName = Mid (sinfo,iFindStart,iFindEnd-iFindStart)
theFile.FileName=getFileName(sFileName)
theFile.FilePath=getFilePath(sFileName)
theFile.FileExt=GetFileExt(sFileName)
'取得文件类型
iFindStart = InStr(iFindEnd,sInfo,"Content-Type: ",1)+14
iFindEnd = InStr(iFindStart,sInfo,vbCr)
theFile.FileType =Mid (sinfo,iFindStart,iFindEnd-iFindStart)
theFile.FileStart =iInfoEnd
theFile.FileSize = iFormStart -iInfoEnd -3
theFile.FormName=sFormName
if not objFile.Exists(sFormName) then
objFile.add sFormName,theFile
end if
else
'如果是表单项目
tStream.Type =1
tStream.Mode =3
tStream.Open
Data_5xsoft.Position = iInfoEnd
Data_5xsoft.CopyTo tStream,iFormStart-iInfoEnd-3
tStream.Position = 0
tStream.Type = 2
tStream.Charset ="gb2312"
sFormValue = tStream.ReadText
tStream.Close
if objForm.Exists(sFormName) then
objForm(sFormName)=objForm(sFormName)&", "&sFormValue
else
objForm.Add sFormName,sFormValue
end if
end if
iFormStart=iFormStart+iStart+1
wend
RequestData=""
set tStream =nothing
End Sub
Private Sub Class_Terminate
if Request.TotalBytes>0 then
objForm.RemoveAll
objFile.RemoveAll
set objForm=nothing
set objFile=nothing
Data_5xsoft.Close
set Data_5xsoft =nothing
end if
End Sub
Private function GetFilePath(FullPath)
If FullPath <> "" Then
GetFilePath = left(FullPath,InStrRev(FullPath, "\"))
Else
GetFilePath = ""
End If
End function
Private function GetFileExt(FullPath)
If FullPath <> "" Then
GetFileExt = mid(FullPath,InStrRev(FullPath, ".")+1)
Else
GetFileExt = ""
End If
End function
Private function GetFileName(FullPath)
If FullPath <> "" Then
GetFileName = mid(FullPath,InStrRev(FullPath, "\")+1)
Else
GetFileName = ""
End If
End function
Public Function MakeFileName(Ext)
If Ext<>"" Then
'''Dim DateYear,DateMonth,DateDay,DateHour,DateMinute,DateSecond,FileRnd
'''DateYear=Year(Now())
'''DateMonth=Month(Now())
'''DateDay=Day(Now())
'''DateHour=Hour(Now())
'''DateMinute=Minute(Now())
'''DateSecond=Second(Now())
'''If Len(DateMonth)<2 Then DateMonth="0" & DateMonth
'''If Len(DateDay)<2 Then DateDay="0" & DateDay
'''If Len(DateHour)<2 Then DateHour="0" & DateHour
'''If Len(DateMinute)<2 Then DateMinute="0" & DateMinute
'''If Len(DateSecond)<2 Then DateSecond="0" & DateSecond
'''Randomize
'''FileRnd=CStr(Int(Rnd()*1000))
'''If Len(FileRnd)=2 Then FileRnd="0" & FileRnd
'''If Len(FileRnd)=1 Then FileRnd="00" & FileRnd
'''MakeFileName=DateYear & DateMonth & DateDay & DateHour & DateMinute & DateSecond & FileRnd & "." & Ext
MakeFileName= wd_name &"_"&ym&"." & Ext
End If
End Function
End Class
Class FileInfo
dim FormName,FileName,FilePath,FileSize,FileExt,FileType,FileStart
Private Sub Class_Initialize
FileName = ""
FilePath = ""
FileSize = 0
FileStart= 0
FormName = ""
FileType = ""
FileExt = ""
End Sub
Public function SaveAs(FullPath)
dim dr,ErrorChar,i
SaveAs=true
if trim(fullpath)="" or FileStart=0 or FileName="" or right(fullpath,1)="/" then exit function
set dr=CreateObject("Adodb.Stream")
dr.Mode=3
dr.Type=1
dr.Open
Data_5xsoft.position=FileStart
Data_5xsoft.copyto dr,FileSize
dr.SaveToFile FullPath,2
dr.Close
set dr=nothing
SaveAs=false
end function
End Class
%>
还是把全部代码贴上了
对upload_5xsoft.inc这个文件不了解!
<%
dim Data_5xsoft
Class upload_5xsoft
dim objForm,objFile,Version
Public function Form(strForm)
strForm=lcase(strForm)
if not objForm.exists(strForm) then
Form=""
else
Form=objForm(strForm)
end if
end function
Public function File(strFile)
strFile=lcase(strFile)
if not objFile.exists(strFile) then
set File=new FileInfo
else
set File=objFile(strFile)
end if
end function
Private Sub Class_Initialize
dim RequestData,sStart,vbCrlf,sInfo,iInfoStart,iInfoEnd,tStream,iStart,theFile
dim iFileSize,sFilePath,sFileType,sFormValue,sFileName
dim iFindStart,iFindEnd
dim iFormStart,iFormEnd,sFormName
Version="化境HTTP上传程序 Version 2.1"
set objForm=Server.CreateObject("Scripting.Dictionary")
set objFile=Server.CreateObject("Scripting.Dictionary")
if Request.TotalBytes<1 then Exit Sub
set tStream = Server.CreateObject("adodb.stream")
set Data_5xsoft = Server.CreateObject("adodb.stream")
Data_5xsoft.Type = 1
Data_5xsoft.Mode =3
Data_5xsoft.Open
Data_5xsoft.Write Request.BinaryRead(Request.TotalBytes)
Data_5xsoft.Position=0
RequestData =Data_5xsoft.Read
iFormStart = 1
iFormEnd = LenB(RequestData)
vbCrlf = chrB(13) & chrB(10)
sStart = MidB(RequestData,1, InStrB(iFormStart,RequestData,vbCrlf)-1)
iStart = LenB (sStart)
iFormStart=iFormStart+iStart+1
while (iFormStart + 10) < iFormEnd
iInfoEnd = InStrB(iFormStart,RequestData,vbCrlf & vbCrlf)+3
tStream.Type = 1
tStream.Mode =3
tStream.Open
Data_5xsoft.Position = iFormStart
Data_5xsoft.CopyTo tStream,iInfoEnd-iFormStart
tStream.Position = 0
tStream.Type = 2
tStream.Charset ="gb2312"
sInfo = tStream.ReadText
tStream.Close
'取得表单项目名称
iFormStart = InStrB(iInfoEnd,RequestData,sStart)
iFindStart = InStr(22,sInfo,"name=""",1)+6
iFindEnd = InStr(iFindStart,sInfo,"""",1)
sFormName = lcase(Mid (sinfo,iFindStart,iFindEnd-iFindStart))
'如果是文件
if InStr (45,sInfo,"filename=""",1) > 0 then
set theFile=new FileInfo
'取得文件名
iFindStart = InStr(iFindEnd,sInfo,"filename=""",1)+10
iFindEnd = InStr(iFindStart,sInfo,"""",1)
sFileName = Mid (sinfo,iFindStart,iFindEnd-iFindStart)
theFile.FileName=getFileName(sFileName)
theFile.FilePath=getFilePath(sFileName)
theFile.FileExt=GetFileExt(sFileName)
'取得文件类型
iFindStart = InStr(iFindEnd,sInfo,"Content-Type: ",1)+14
iFindEnd = InStr(iFindStart,sInfo,vbCr)
theFile.FileType =Mid (sinfo,iFindStart,iFindEnd-iFindStart)
theFile.FileStart =iInfoEnd
theFile.FileSize = iFormStart -iInfoEnd -3
theFile.FormName=sFormName
if not objFile.Exists(sFormName) then
objFile.add sFormName,theFile
end if
else
'如果是表单项目
tStream.Type =1
tStream.Mode =3
tStream.Open
Data_5xsoft.Position = iInfoEnd
Data_5xsoft.CopyTo tStream,iFormStart-iInfoEnd-3
tStream.Position = 0
tStream.Type = 2
tStream.Charset ="gb2312"
sFormValue = tStream.ReadText
tStream.Close
if objForm.Exists(sFormName) then
objForm(sFormName)=objForm(sFormName)&", "&sFormValue
else
objForm.Add sFormName,sFormValue
end if
end if
iFormStart=iFormStart+iStart+1
wend
RequestData=""
set tStream =nothing
End Sub
Private Sub Class_Terminate
if Request.TotalBytes>0 then
objForm.RemoveAll
objFile.RemoveAll
set objForm=nothing
set objFile=nothing
Data_5xsoft.Close
set Data_5xsoft =nothing
end if
End Sub
Private function GetFilePath(FullPath)
If FullPath <> "" Then
GetFilePath = left(FullPath,InStrRev(FullPath, "\"))
Else
GetFilePath = ""
End If
End function
Private function GetFileExt(FullPath)
If FullPath <> "" Then
GetFileExt = mid(FullPath,InStrRev(FullPath, ".")+1)
Else
GetFileExt = ""
End If
End function
Private function GetFileName(FullPath)
If FullPath <> "" Then
GetFileName = mid(FullPath,InStrRev(FullPath, "\")+1)
Else
GetFileName = ""
End If
End function
Public Function MakeFileName(Ext)
If Ext<>"" Then
'''Dim DateYear,DateMonth,DateDay,DateHour,DateMinute,DateSecond,FileRnd
'''DateYear=Year(Now())
'''DateMonth=Month(Now())
'''DateDay=Day(Now())
'''DateHour=Hour(Now())
'''DateMinute=Minute(Now())
'''DateSecond=Second(Now())
'''If Len(DateMonth)<2 Then DateMonth="0" & DateMonth
'''If Len(DateDay)<2 Then DateDay="0" & DateDay
'''If Len(DateHour)<2 Then DateHour="0" & DateHour
'''If Len(DateMinute)<2 Then DateMinute="0" & DateMinute
'''If Len(DateSecond)<2 Then DateSecond="0" & DateSecond
'''Randomize
'''FileRnd=CStr(Int(Rnd()*1000))
'''If Len(FileRnd)=2 Then FileRnd="0" & FileRnd
'''If Len(FileRnd)=1 Then FileRnd="00" & FileRnd
'''MakeFileName=DateYear & DateMonth & DateDay & DateHour & DateMinute & DateSecond & FileRnd & "." & Ext
MakeFileName= wd_name &"_"&ym&"." & Ext
End If
End Function
End Class
Class FileInfo
dim FormName,FileName,FilePath,FileSize,FileExt,FileType,FileStart
Private Sub Class_Initialize
FileName = ""
FilePath = ""
FileSize = 0
FileStart= 0
FormName = ""
FileType = ""
FileExt = ""
End Sub
Public function SaveAs(FullPath)
dim dr,ErrorChar,i
SaveAs=true
if trim(fullpath)="" or FileStart=0 or FileName="" or right(fullpath,1)="/" then exit function
set dr=CreateObject("Adodb.Stream")
dr.Mode=3
dr.Type=1
dr.Open
Data_5xsoft.position=FileStart
Data_5xsoft.copyto dr,FileSize
dr.SaveToFile FullPath,2
dr.Close
set dr=nothing
SaveAs=false
end function
End Class
%>
还是把全部代码贴上了
对upload_5xsoft.inc这个文件不了解!
#7
有人能帮帮吗?
#8
不能用 request.form 取值的,用了之后 upload_5xsoft 就取不到值了
要全部用 upload_5xsoft 取值
对象赋值用set, 一般变量赋值不需要Set
set upload = new upload_5xsoft
fl_name = upload.form("fl_name")
wdbh = upload.form("wdbh")
wd_name = upload.form("wd_name")
img_name_1 = upload.form("img_name_1")
ym = upload.form("ym")
要全部用 upload_5xsoft 取值
对象赋值用set, 一般变量赋值不需要Set
set upload = new upload_5xsoft
fl_name = upload.form("fl_name")
wdbh = upload.form("wdbh")
wd_name = upload.form("wd_name")
img_name_1 = upload.form("img_name_1")
ym = upload.form("ym")
#9
今天也遇到这个问题,www.fs526.com这个网站,
#10
这个问题嘛,不好说啊,你可以去这个站上看看,比较全www.bycxlw.com