Quantcast
Channel: SCN : Document List - Scripting Languages
Viewing latest article 6
Browse Latest Browse All 100

REPL Interface for VBScript

$
0
0

Hello community,

 

more and more moves Read-Eval-Print-Loop (REPL) shells in the focus of scripting languages. You can find more information about REPL here.

 

Here is a tiny REPL shell for VBScript:

 

'-Begin-----------------------------------------------------------------

'-

'- REPL interactive shell for VBScript

'- (REPL = Read Eval Print Loop)

'- Call it with CSCRIPT REPL.VBS //NOLOGO

'-

'-----------------------------------------------------------------------

 

  WScript.StdOut.Write("Welcome to REPL interactive shell for " & _

    "VBScript" & vbCrLf)

 

  repl_Quit = False

  Do

 

    If repl_SubFlag = False Then

      WScript.StdOut.Write(vbCrLf & "> ")

    Else

      WScript.StdOut.Write("  ")

    End If

 

    repl_Line = WScript.StdIn.ReadLine

 

    repl_Pos = InStr(repl_Line, " ")

    If repl_Pos > 0 Then

      repl_Cmd = Trim(Left(repl_Line, repl_Pos))

    Else

      repl_Cmd = repl_Line

    End If

 

    If repl_SubFlag = True Then

      repl_Lines = repl_Lines & repl_Line & vbCrLf

    End If

 

    Select Case LCase(repl_Cmd)

      Case "quit"

        repl_Quit = True

      Case "print", "echo"

        On Error Resume Next

        Err.Clear

        Execute("WScript.Echo(" & _

          Trim(Right(repl_Line, Len(repl_Line) - repl_Pos)) & ")")

        If Err.Number <> 0 Then

          WScript.Echo(Err.Description)

        End If

        On Error Goto 0

      Case "sub", "function", "class"

        repl_SubFlag = true

        repl_Lines = repl_Line & vbCrLf

      Case Else

        If repl_SubFlag = False Then

          On Error Resume Next

          Err.Clear

          Execute repl_Lines & repl_Line

          If Err.Number <> 0 Then

            WScript.Echo(Err.Description)

          End If

          On Error Goto 0

          repl_Lines = ""

        End If

    End Select

 

  Loop While repl_Quit = False

 

'-End-------------------------------------------------------------------

 

Start this script with cscript repl.vbs //nologo from the command line.

 

002.jpg

With this shell you have the possiblity to check easily commands, sub routines, functions etc. etc. etc.

 

Enjoy it.

 

Cheers

Stefan


Viewing latest article 6
Browse Latest Browse All 100

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>