Wednesday, August 3, 2016

Running VBScripts standalone with Command Prompt

Over the past few years I've had to do a bunch of little vbscripts to create custom actions for Datacap. Recently I found a problem with a script and a friend showed me a quick little way to run my script standalone.
Simply put the script in a file with a vbs extension and use the command line to run it with cscript command.  This was available on my default windows.  Now with my limited memory I'll hopefully remember this blog post so I can come back and 'remember' how to do it.

Now, the other issue that I haven't been able to solve is why 2.28 != 2.28.  It sure seems like a type problem, but I forced the types to Double and that didn't help.

Dim sCResult
Dim sExpression

sExpression = "(760.27 + 64.56) = 824.83"
sExpression = "(1.27 + 1.01) = 2.28"

'sExpression = "(1.27 + 1.01) = (1.27 + 1.01)"

wscript.echo(" Evaling: " & Trim(sExpression))
wscript.echo( Eval("1.27 + 1.01") )
wscript.echo( Eval("2.28") )
sCResult = Eval(Trim(sExpression))

wscript.echo("Eval returns: '" & sCResult & "' ")

sExpression2 = "CDbl((1.27 + 1.01)) = CDbl(2.28)"
wscript.echo("")
wscript.echo("")
wscript.echo( Eval("CDbl(2.28)") )
wscript.echo( Eval("CDbl(1.27 + 1.01)") )
wscript.echo(" Evaling: " & Trim(sExpression2))
sCResult2 = Eval(Trim(sExpression2))
wscript.echo("Eval returns: '" & sCResult2 & "' ")

Running VBScripts standalone with Command Prompt

Over the past few years I've had to do a bunch of little vbscripts to create custom actions for Datacap. Recently I found a problem with a script and a friend showed me a quick little way to run my script standalone.
Simply put the script in a file with a vbs extension and use the command line to run it with cscript command.  This was available on my default windows.  Now with my limited memory I'll hopefully remember this blog post so I can come back and 'remember' how to do it.

Now, the other issue that I haven't been able to solve is why 2.28 != 2.28.  It sure seems like a type problem, but I forced the types to Double and that didn't help.

Dim sCResult
Dim sExpression

sExpression = "(760.27 + 64.56) = 824.83"
sExpression = "(1.27 + 1.01) = 2.28"

'sExpression = "(1.27 + 1.01) = (1.27 + 1.01)"

wscript.echo(" Evaling: " & Trim(sExpression))
wscript.echo( Eval("1.27 + 1.01") )
wscript.echo( Eval("2.28") )
sCResult = Eval(Trim(sExpression))

wscript.echo("Eval returns: '" & sCResult & "' ")

sExpression2 = "CDbl((1.27 + 1.01)) = CDbl(2.28)"
wscript.echo("")
wscript.echo("")
wscript.echo( Eval("CDbl(2.28)") )
wscript.echo( Eval("CDbl(1.27 + 1.01)") )
wscript.echo(" Evaling: " & Trim(sExpression2))
sCResult2 = Eval(Trim(sExpression2))
wscript.echo("Eval returns: '" & sCResult2 & "' ")