为了账号安全,请及时绑定邮箱和手机立即绑定

请问在asp中,为什么mid()函数有时出错,有时不会出错?

请问在asp中,为什么mid()函数有时出错,有时不会出错?

潇潇雨雨 2021-11-20 15:11:27
错误类型:Microsoft VBScript 运行时错误 (0x800A0005)无效的过程调用或参数: 'Mid'/zhuaqu1.asp, 第 51 行我的程序如下,<%@language=vbscript%><!--#include file=conn22.asp--><html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>新建网页 1</title></head><body><%function getHTTPPage(url) '通过组件Msxml2.XMLHTTP抓取网页内容on error resume next dim http set http=Server.createobject("Msxml2.XMLHTTP") Http.open "get",url,falseHttp.send() if Http.readystate<>4 then exit function getHTTPPage=bytes2BSTR(Http.responseBody) set http=nothing if err.number<>0 then err.Clear end functionFunction bytes2BSTR(vIn) '把抓取到的内容转化为文本dim strReturn dim i,ThisCharCode,NextCharCode strReturn = "" For i = 1 To LenB(vIn) ThisCharCode = AscB(MidB(vIn,i,1)) If ThisCharCode<&H80 Then strReturn = strReturn & Chr(ThisCharCode) Else NextCharCode = AscB(MidB(vIn,i+1,1)) strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode)) i = i + 1 End If Next bytes2BSTR = strReturn End Functiondim xurlxurl="http://sx.zsedu.net/"strContent=getHTTPPage(xurl)strContent=Replace(strContent," ","")pos1=1do while pos1 > 0%><%pos1 = InStr(1, strContent, "<", vbTextCompare)pos2 = InStr(1, strContent, ">", vbTextCompare)if pos1 > 0 and pos2 > 1 thentitle = Mid( strContent, pos1, pos2 - pos1+1 )strContent=Replace(strContent,title,"")end if%><%loop %><%strContent=Replace(strContent," ","")response.write(strContent)dim visitorswhichfile=server.mappath("zhuaqu\zhuaqu.txt")set qfs=server.createobject("Scripting.FileSystemObject")set thisfile=qfs.opentextfile(whichfile)visitors=thisfile.readlinethisfile.closevisitors=strContentvisitors=Replace(visitors," ","")set out=qfs.createtextfile(whichfile)out.writeline(visitors)out.closeset fs=nothingstrtable="b"set rs=server.createobject("adodb.recordset")rs.open strtable,conn22,1,3rs.addnewrs("pinming")=strContentrs("huohao")="11"rs("jiage")="sa"rs("miaosu")="df"rs.updaters.closeset rs=nothing%></body></html>
查看完整描述

2 回答

?
翻翻过去那场雪

TA贡献2065条经验 获得超14个赞

我觉得我是找到原因了,http://sx.zsedu.net/页面内容里有单独出现的">",如语句:if(dypopLayer.filters.Alpha.opacity>0)中就含有单独的">",故pos1与pos2并不是如你想像中那样完全配套的!

修改也很简单,程序不需要太大变化,只需要把
pos1=1
do while pos1 > 0
%>
<%
pos1 = InStr(1, strContent, "<", vbTextCompare)
pos2 = InStr(1, strContent, ">", vbTextCompare)
if pos1 > 0 and pos2 > 1 then
title = Mid( strContent, pos1, pos2 - pos1+1 )
strContent=Replace(strContent,title,"")
end if
%>
<%
loop
%>

改为:
pos1=1
pos2=1
do while pos1 > 0
%>
<%
pos1 = InStr(1, strContent, "<", vbTextCompare)
pos2 = InStr(pos2+1, strContent, ">", vbTextCompare)
if pos1 > 0 and pos2 > 1 and pos2 > pos1 then
title = Mid( strContent, pos1, pos2 - pos1+1 )
strContent=Replace(strContent,title,"")
pos2=1
end if
%>
<%
loop
%>



查看完整回答
反对 回复 2021-11-23
?
慕尼黑8549860

TA贡献1818条经验 获得超11个赞

Mid函数是从第一个字符开始取值的
如果 pos1 = InStr(1, strContent, "<", vbTextCompare) 这句话得到的POS1小于1的话,程序Mid函数当然就会报错了

查看完整回答
反对 回复 2021-11-23
  • 2 回答
  • 0 关注
  • 370 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信