Are you using vbscript?

Okay, this was a fun time travel... Remember that post not even a week ago when I talked about our working museum of code at my current workplace?

That's (not surprisingly) relevant again, as I was reviewing some old .aspx code and incrementally refactoring out all the Response.Writes so we could move it into the 21st century. That meant trying to remember some vbscript string operators from my past life as a classic ASP dev.

I was trying to figure out how to test quick snippets of VB code and found this "gem" of a script (not in Ruby, to be clear ;^)) that allows you to have a limited interactive shell for vbscript:

do while true
    wscript.stdout.write(">>>") 
    ln = wscript.stdin.readline 

    if lcase(trim(ln)) = "exit" then exit do
        
    err.clear 
    
    ln = "str = """":" & ln & ":wscript.echo(""#"" & str & ""#"")"

    execute ln 
    
    if err.number <> 0 then 
        wscript.echo(err.description) 
    end if
loop

(Yes, I added the echo for str overhead to save some typing if I'm playing with strings)

It requires a session to be a single line, which means you have to separate commands with :, but it's fairly useful in a pinch. Admittedly I wasn't as careful in that code with variable and keyword casing as I used to be when I used to code in vbscript... last century. ;)

Example usage:

c:\temp>cscript vbsimple.vbs
Microsoft (R) Windows Script Host Version 5.812
Copyright (C) Microsoft Corporation. All rights reserved.

>>>str = "   asdfASDFasDF     ":str = Trim(LCase(str))
#asdfasdfasdf#
>>>str =
Syntax error
>>>

There's an even fancier script over here (c2013) that allegedly allows multiple line entries, but I wasn't able to get that running with a trivial time expenditure.

It would be easy enough to make the one above a multiline shell, but for now, enjoy as-is, I reckon.

Labels: ,