Why vbscript Mid function shows error ‘Invalid Procedure Call or argument : Mid’

asp-classicvbscript

Hi Below is my code of ASPClassic, in which csvData is a very large string containing variable.Now in this At line where Mid function is call error 'Invalid Procedure Call or argument : Mid' occur why this happens…

Dim dataLen 
    Dim fromLen 
       Dim toLen 
       Dim slab 
       Dim totalPass 

       dataLen =len(csvData)
       fromLen =0
       toLen =100000
       slab =100000
       totalPass =(dataLen/slab)
    if (dataLen Mod slab)>0  then
        totalPass=totalPass+1
    end if
    Dim i
    For i = 0 To dataLen
        i=toLen
        if toLen > dataLen then
            toLen=dataLen
        end if 
       Response.Write Mid(csvData,fromLen,toLen)
        fromLen=toLen
        toLen=toLen+slab
    Next

Best Answer

I think that your fromLen is 0, when you call Mid() for the first time:

>> m = Mid("x", 0, 1)
>>
Error Number:       5
Error Description:  Invalid procedure call or argument

Try to initialize with:

fromLen = 1
Related Topic