sen*_*hin 3 vbscript asp-classic
我有一个功能(见下文),它完美地工作.我最近将我的代码移动到另一台服务器,我没有更改任何内容.它无法在新服务器上运行.
Microsoft VBScript runtime error '800a0005'
Invalid procedure call or argument: 'Mid'
/calculate.asp, line 416
Run Code Online (Sandbox Code Playgroud)
当我检查416行时,我得到了这个:
Dim result3: result3 = Mid(o3.responseText, Basla3, Bitir3)
Run Code Online (Sandbox Code Playgroud)
这是完整的功能:
<%
Function xyz()
Dim o3: Set o3 = Server.CreateObject("MSXML2.ServerXMLHTTP")
Dim o_date3: o_date3 = split(EndingDate, ".")
Dim s_date3
If (Len(o_date3(2)) = 4) Then
s_date3 = o_date3(2)
Else
s_date3 = "20" & o_date3(2)
End If
If (Len(o_date3(1)) = 2) Then
s_date3 = s_date3 & o_date3(1)
Else
s_date3 = s_date3 & "0" & o_date3(1)
End If
If (Len(o_date3(0)) = 2) Then
s_date3 = s_date3 & o_date3(0)
Else
s_date3 = s_date3 & "0" & o_date3(0)
End If
Dim s3: s3 = "<soapenv:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:urn=""urn:AntTransferWSIntf-IAntTransferWS""><soapenv:Header/><soapenv:Body><urn:EURCurrency soapenv:encodingStyle=""http://schemas.xmlsoap.org/soap/encoding/""><DateStr xsi:type=""xsd:string"">" + s_date3 + "</DateStr></urn:EURCurrency></soapenv:Body></soapenv:Envelope>"
o3.Open "POST", serviceUrl, False
o3.setRequestHeader "Content-Type", "text/xml"
o3.setRequestHeader "Connection", "close"
o3.setRequestHeader "SOAPAction", " "
o3.send s3
Dim hataVarMiBasla3: hataVarMiBasla3 = (InStr(1, o3.responseText, "<faultstring>", vbTextCompare)) + 13
If (hataVarMiBasla3 > 13) Then
Dim hataVarMiBitir3: hataVarMiBitir3 = (InStr(1, o3.responseText, "</faultstring>", vbTextCompare)) - hataVarMiBasla3
Dim hata3: hata3 = Mid(o3.responseText, hataVarMiBasla3, hataVarMiBitir3)
KurGetir = hata3
Else
Dim Basla3: Basla3 = (InStr(1, o3.responseText, """xsd:double"">", vbTextCompare)) + 13
Dim Bitir3: Bitir3 = (InStr(1, o3.responseText, "</return>", vbTextCompare)) - Basla3
Dim result3: result3 = Mid(o3.responseText, Basla3, Bitir3)
xyz = CDbl(Replace(result3, ".", mstrComma))
End If
Set o3 = Nothing
End Function
%>
Run Code Online (Sandbox Code Playgroud)
为什么我收到此错误?
中(字符串,开始[,长度])
不是官方参考,但根据我的经验,如果你得到那个错误
看看错误行和相关的错误.
Dim Basla3: Basla3 = (InStr(1, o3.responseText, """xsd:double"">", vbTextCompare)) + 13
Dim Bitir3: Bitir3 = (InStr(1, o3.responseText, "</return>", vbTextCompare)) - Basla3
Dim result3: result3 = Mid(o3.responseText, Basla3, Bitir3)
Run Code Online (Sandbox Code Playgroud)
假设o3.responseText为空,因为您的代码不会检查响应是否为空.
Basla3不能少于13 InStr() + 13,所以这不是问题.
然而,Bitir3根据InStr() - Basla3(Basla3评估为13),它似乎可以小于零.
继续假设,(InStr(1, o3.responseText, "</return>", vbTextCompare))评估为0,然后与- Basla3它一起评估为-13.
田田!违反规则2,长度不能小于零.
您的代码存在的问题是,没有检查响应长度和响应状态.如果响应为空,请考虑以下事项:
简而言之,您应该优化代码并确保存在xml响应.
至少使用类似的东西:
o3.Send
If o3.readyState = 4 And o3.status = 200 Then
If Len(o3.responseText) > 0 Then
'response is ready to parse
Else
'response status is ok but empty
End If
Else
'request failed
End If
Run Code Online (Sandbox Code Playgroud)
顺便说一句,由于你的请求是一个肥皂调用,我强烈建议通过使用DomDocument等解析xml响应来完成这项工作.
更换小数点,使用Mid & InStr对检查节点存在只是麻烦和不好的做法.
| 归档时间: |
|
| 查看次数: |
7313 次 |
| 最近记录: |