Friday, August 8, 2008

VBScript - Numbers as CmdLine Arguments

While I was preparing code for Excel Automation , I decided to pass the few integer values. Always the script got failed, if I pass the integer values through arguments. But the script went through fine, if I directly pass the parameters in that function call. While debugging the code, I was not able to find the reason for failure. I did Google search and unable to get the right solution.

Later I analyzed the code and put the simple conversion, while getting the arguments. The code worked as expected.

  1. To Convert String to Integer --> iStartRow = CInt (WScript.Arguments.Item(1))

  2. To Convert String to Double --> dExpVal = CDbl (WScript.Arguments.Item(2))

  3. To Convert String to Number --> nRowRange = Val (WScript.Arguments.Item (3))

To know more about the Command Line Arguments to VBScript, go through this post - Passing Command Line Arguments .

If you are unable to run any VBScript, See my old post - Unable to run VBScript / WScript / CScript in Windows XP .

No comments: