本页主题: Why do I get 'Invalid procedure call or argument'? 打印 | 加为IE收藏 | 复制链接 | 收藏主题 | 上一主题 | 下一主题

Mike
群熵工程师
级别: 管理员


精华: 7
发帖: 951
威望: 714 点
金钱: 6601 RMB
贡献值: 0 点
好评度: 611 点
在线时间:1404(小时)
注册时间:2003-11-28
最后登录:2017-02-24

 Why do I get 'Invalid procedure call or argument'?

This often happens because you used a VBScript "friendly name" constant in place of its integer equivalent. Visual Basic understands these friendly names, such as FileSystemObject's 'forAppending' and 'forWriting' constants. 
 
An easy solution is to add this line to any include files you use in every page (or else add it at the top of every page, if you don't have a common header in your application): 
 
<% 
    Const ForReading = 1, ForWriting = 2, ForAppending = 8 
%>
 


 
Another possible cause is trying to use a string operation (like Mid(), InStr(), Left() or Right()) on a NULL value. So for example: 
 
<% 
    response.write Left(rs("column"), 10) 
%>
 
Should be: 
 
<% 
    if len(rs("column")) > 0 then 
        response.write Left(rs("column"), 10) 
    else 
        response.write " " 
    end if 
%>
 
If you're having these problems with NULL values coming out of a database, see Article #2150
 


 
Another possibility is that you are coming over from JavaScript, or otherwise think that string lengths are 0-based. The following code sample will cause this error: 
 
<% 
    str = "foo" 
    response.write Mid(str, 0, 1) 
 
%>
 
Similarly, passing a starting argument of 0 to the Instr() function will cause the same error. To solve this problem, always start at 1 for string parsing in VBScript. 
 


 
Still one more possibility is that you have unexpected characters in an FSO writeline call. I recently came across this when using MSXML to write out contents of dynamic ASP files into static HTML files. I had this: 
 
<% 
    set fs = fso.CreateTextFile("blat.htm", true) 
    fs.writeline xmlHTML 
%>
 
When I ran this code, I received the above error. When I added the unicode format designator, as follows, everything worked fine: 
 
<% 
    set fs = fso.CreateTextFile("blat.htm", true, -1
    fs.writeline xmlHTML 
%>

顶端 Posted: 10-01-11 22:01 | [楼 主]
Mike
群熵工程师
级别: 管理员


精华: 7
发帖: 951
威望: 714 点
金钱: 6601 RMB
贡献值: 0 点
好评度: 611 点
在线时间:1404(小时)
注册时间:2003-11-28
最后登录:2017-02-24

 

顶端 Posted: 10-01-11 22:02 | 1 楼
帖子浏览记录 版块浏览记录
群熵信息 - 技术讨论区 » WEB脚本技术进阶

Total 0.015763(s) query 5, Time now is:10-18 10:11, Gzip enabled
Powered by PHPWind v6.3.2 Certificate Code © 2003-08 PHPWind.com Corporation

上海服务器租用 杭州世导双线服务器托管 云主机 VPS