1

Background

I'm a tech writer but have dabbled in coding for many years now. For work, I need to test about a hundred different ancient script samples. The samples are stored in our documentation. They are in written in Basic (technically, in Cypress Enable BASIC, but it's essentially very similar if not identical to Basic scripting). I need to test them and fix any that are broken.

I want to set up Visual Studio Code to run these because I love VSC as it has a lot of benefits over the very old and vanilla scripting editor included with our product that I've been using.

My Need

Mainly, I need to be able to copy and paste the code I want to test into VSC into a simple .bas file and then run and test the code inside VSC with code coloring, code running, and a debugger. Intellisense would also be helpful. I can get color coding, but getting it to run and debug isn't working.

What I've Tried and Other Notes

I've already spent hours trying to set something up, but can't figure it out.

  • I have Windows 10
  • From something I found online, I've mapped this folder C:\Windows\Microsoft.NET\Framework64\v3.5 to my system's Path Environment Variable. (where <user> is my user name).
  • I've also tried different vbscript and vba related extensions, but have since uninstalled them as nothing seemed to resolve this very basic (no pun intended) problem.
  • I've searched various posts online and in this site, but haven't found a solution yet.
  • I tried enabling Run in Terminal in Code-runner to see if that made any difference.

Something is wrong, as I consistently get errors. For example, with Code Runner extension installed, if I try to run this very simple vbscript to show a test message box...

Sub Main ()
    Dim testString
    testString = "Meh... Will it work?"
    MsgBox testString
End Sub

...I get this result in my VSC Output window:

[Running] cscript //Nologo "d:\Temp\vbscripttest.bas"

[Done] exited with code=0 in 0.174 seconds

I find very little info searching on code=0 error that is useful.

My script is in my d:\temp folder. I don't know if that makes a difference. If I try running the .bas file from the File Explorer window directly by double-clicking on it, nothing happens. Though from the icon style, it appears to be mapped to VBScript.

I gather either Windows or vbcode or both can't find the vbscripting goodness that makes things work, though I thought pointing the path variable to C:\Windows\Microsoft.NET\Framework64\v3.5 would fix that.

After two days of pulling my eyebrows out using our product's internal script editor to test my scripts (my hair has long since gone), I am hankering for some good old fashioned debugging support in my favorite code editor!

What do you recommend I do to get things working? Thank you in advance for your help.

Jared
  • 179
  • 1
  • 10
  • 3
    My guess is that `code=0` is a "success" code indicating that the program has run to completion without errors (similar to a C or C++ program returning 0 to the operating system). The problem that I see here is that you're trying to run a GUI element (MessageBox) from a prompt, which doesn't have the support to display graphics. Try it with printing just plain text. As far as how to get the GUI to pop up, even outside of VS Code, I'm not sure. Fun project, though. – jonsca May 27 '22 at 21:45
  • In terms of Intellisense, etc., you could probably write your own language server https://code.visualstudio.com/api/language-extensions/language-server-extension-guide, maybe with a parser that Cyprus could provide for you. – jonsca May 27 '22 at 21:50
  • 1
    Thanks @jonsca. Intellisence isn't a deal breaker. I can figure things out from the documentation I'm using or online. I mainly just need the ability to run and debug. But it sound like you're saying VS Code doesn't have the ability to show gui elements. I wasn't aware of that. I thought if an extension said it supported vbscript it'd work. I do have access to full blown Visual Studio. I was just looking for a simpler, light-weight solution. – Jared May 27 '22 at 21:54
  • I tried using `print testString` instead of the MsgBox command, and it gives the same message, and the expected string still does not show in Output, Terminal, or Debug Console. If I enable terminal running in the Code Runner extension, it shows this: `PS D:\Temp> cd "d:\Temp" PS D:\Temp> cscript //Nologo "d:\Temp\vbscripttest.bas" PS D:\Temp>` – Jared May 27 '22 at 22:07
  • How about if you change your terminal type to a "cmd" instead of a Powershell one? It's in the settings somewhere. – jonsca May 27 '22 at 22:13
  • @user692942 Well, after following recommendation from user18521918, the MsgBox statement actually does work. My examples that I'm testing and reworking also use MsgBox, and I don't want to have to change them to echo as echo won't work in the Cypress Enable scripting component that's used inside of our product. – Jared Jun 01 '22 at 16:37

1 Answers1

2

Your sample program is running successfully. In that file there is no code in the code path. VBScript in a top level language (unlike VBA). That means code runs outside of a sub or function.

So insert before the first line Main to call Main. Or lose the Sub ... End Sub for VBScript. In VBA/VB6 you would choose Sub Main as the startup sub in Properties.

While this is not your problem, just to be complete, if you start a script in CScript or WScript using //b command line parameter then message boxes are not displayed. See CScript /?.

user18521918
  • 102
  • 1
  • 1
  • 3
  • Thank you for your answer common sense answer. This did the trick. I added `call Main` above the Main() procedure and the message box appeared. So simple! I can't believe I spent more than five hours trying to figure that out. Uggg. – Jared Jun 01 '22 at 16:28
  • Now that it runs successfully, anyone know how would I enable a debugger? – Jared Jun 01 '22 at 16:31
  • 1
    https://stackoverflow.com/questions/10980171/how-do-i-get-microsoft-script-debugger-to-work-with-64-bit-windows-7 and ` //x` command line switch to `wscript.exe`. – user18521918 Jun 01 '22 at 19:48
  • Hi @user18521918. Thanks for the link, unfortunately, on the URL you posted, the primary Microsoft site on the original post there no longer offers the debugger. A comment posted below it supposedly offers the debugger via a MediaFire download link. But I'd feel more comfortable installing an accepted extension inside of VSCode if there is one. – Jared Jun 03 '22 at 20:35
  • 1
    VBScript is legal VBA. Therefore use an Office VBA editor. Your script just needs to be in a `Sub Main`. You also won't have access to the `WScript` object but do to the sub objects of `WScript`. – user18521918 Jun 03 '22 at 20:44
  • 1
    PS The Microsoft Script Debugger is useless. It only debugs one script once through before needing to be closed and reopened. – user18521918 Jun 03 '22 at 20:48