亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

請問在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 關注
  • 414 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號