This is as days pass by, by Stuart Langridge

And this is VBScript interactive shell, written , and concerning Uncategorized

One of the things I really love about Python is the interactive shell; when I think “how do I do X in Python?” then I can just drop to a shell, type “python“, and then try stuff out. I can’t do that in VBScript, and it annoys me. So: an interactive VBScript shell.
do while true
  wscript.stdout.write(">>> ")
  ln = wscript.stdin.readline
  if lcase(trim(ln)) = "exit" then exit do
  on error resume next
  err.clear
  execute ln
  if err.number <> 0 then wscript.echo(err.description)
  on error goto 0
loop
Note that this is totally daft and it doesn’t do anythng complex at all. No line continuations. No cleverness. But it helps me to answer the sorts of questions I come up with a lot, like “does a string with length > 0 evaluate to True?” without having to create a .vbs file and run it. You need to run this from the command line with cscript.

Comments

Roberto

Do you have a Fortran version? :)


I agree with you, the interactive shell is one of the best things about Python. Everytime I'm coding in Fortran (really, I do that) I almost get crazy.

Rob Eberhardt, Slingshot Solutions

Ha, great minds think alike!


I wrote a GUI (WScript) version of this a while back.  Here's the whole thing (hope it displays right):

<pre><code>

OPTION EXPLICIT


DIM strCodeToExec

strCodeToExec = "msgbox Now()"


DO WHILE strCodeToExec<>""

strCodeToExec = InputBox("Enter VBS code to execute", "WSH Prompt", strCodeToExec)

IF strCodeToExec<>"" THEN

on error resume next


execute(strCodeToExec)


IF err.Number<>0 THEN

call msgbox("Error #" & err.number & vbCRLF & err.description, vbExclamation, "Run Error")

END IF


on error goto 0

END IF

LOOP

</code></pre>


It just prompts for code (with an inputbox), execs that code & then asks for more.  Quite handy.


Btw, it's downloadable as "WSHPrompt" at http://slingfive.com/pages/tools/.

Martin

How does the original script work?
There’s no such object as “wscript“. How do you create such an object?

I’d really love to see a working version of this.

Thanks,
Martin

sil

Martin: put the code in a file called “vbs.vbs“, and then run it with “cscript //nologo vbs.vbs“.

Chris Patti

Martin, this is an *incredibly* useful script. I find being able to prototype my code interactively to be such a huge productivity win - I think *every* interpreted language should provide such a thing.

Thanks so much!

-Chris

This website belongs to Stuart Langridge. Contact details are available. Don't eat yellow snow. Valid HTML5, at least in theory, except for the bits that aren't because I'm that futuristic that I'm ahead of the spec, oh yes. HTML5 help from Bruce Lawson, among others. Fonts from the superb FontSquirrel. End.