Tuesday, July 11, 2006

Fix for VBScript Error: Invalid procedure call or argument: 'Mid'

After long long time i have touched VBScript and was trying to traverse string character by character. I came across some weird error or may be i have not read VBScript for long long time.

When you try to traverse string character by character, never start with index 0 otherwise you will get the above error

Invalid procedure call or argument: 'Mid'

Along with this you will get argument 2 is invalid or something like that.

To traverse string character by character in VBScript use the following snippet of code:

/**

inputString = "String traversal in VBScript";
stringLength = len(inputString)

For i = 1 To stringLength
mychar = Mid(inputString, i, 1 )
WScript.Echo "My character is "+mychar
Next

*/

This is one of the way to traverse string in VBScript.

No comments: