Friday, June 29, 2012

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

After a long searching I have found this link: http://classicasp.aspfaq.com/files/directories-fso/why-do-i-get-invalid-procedure-call-or-argument.html

it pointed out some possible cause and I have found that the last one is useful for my case.

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
%>

Monday, May 21, 2012

Some experience with QTP 11

I have encountered many QTP's issues since working with AUT (dot Net 4.0) both 32 bit and 64 bit, QTP will intend to crash after long run ...solution I found here it: update latest hotfix for QTP.