What is the difference between VB and VBScript?
-
I'm stripping the Java/JavaScript bit out of your question, as it's irrelevant and duplicates an existing question. For the answer, see: stackoverflow.com/questions/245062/…– Shog9Sep 5, 2009 at 19:15
-
Related post - What is the difference between vbscript and vb.net?– RBTFeb 20, 2019 at 12:11
-
VBA features not in VBScript and VBScript features not in VBA: csidata.com/custserv/onlinehelp/vbsdocs/vbsfea1.htm– GSergJun 10, 2019 at 13:20
6 Answers
VB is a full-fledged programming language which can be used to create compiled applications, while VBScript is a sub-set of VB and is a scripting language that can be used to run a set of commands, similar to an old-school DOS batch file. Generally, a scripting language can not be used to create a full-fledged binary application and it can not be compiled down to a executable binary file.
This is a very old question, but existing answers are outrageously vague, and/or fail to identify the most important stuff, when they're not just plain wrong. Not going to repeat what other answers already indicate, but the following differences are missing from the other answers:
Scopes
VBScript code doesn't need procedure scopes: it can be written as a [drumroll] script that just executes a bunch of procedural operations top-to-bottom.
In VB6/VBA executable statements can only exist inside procedure scopes.
Types
In VBScript everything (variables, function return values, etc.) is a Variant
(i.e. pretty much a duck, like in JavaScript). It is illegal to declare an explicit type when declaring a variable. The As
keyword is illegal!
In VB6/VBA everything defaults to an implicit Variant
, but good VB6/VBA code uses explicit types where applicable.
-
Scopes aren't missing, VBScript still has Global, Class and Procedure scoped variables. Personally, if I'm writing VBScript regardless of whether it can just be written as a strew of commands, I prefer to give it structure. May 24, 2017 at 22:39
-
2@Lankymart I'm not saying scopes are missing - I'm saying they don't have to exist. Which is quite a major difference between it and other flavors, where executable statements must be inside a procedure scope. I meant "missing" as in "missing from other answers". May 24, 2017 at 22:41
-
By definition, anything written outside of a procedure or function in VBScript is in the Global scope. Oct 28, 2020 at 9:48
-
@Lankymart that's 3.5 years later... but yes? The point about scopes remains: VBScript lets you have executable statements outside of a procedure body, and VB6/VBA does not, it's a compile-time error to have that. Oct 28, 2020 at 13:43
VBScript is a variety of VB, just as VB6, VBA, and VB.NET are. They're all different, some of them dramatically so.
VBScript is a "lightweight" subset of Visual Basic with limited syntax that is used for scripting purposes (like routine task automation) rather than application development.
While Visual Basic code is compiled into binary executables, VBScript code is interpreted and runs within a host environment (e.g. Windows Script Host or Internet Explorer).
Also VBScript's code can be ran in VB6. Maybe that confuses you.
But all VB6's codes can't be ran in VBScript.
-
2Wrong. VBScript executable can be written outside of procedure scopes; not in VB6. May 24, 2017 at 21:40
-
@Mat's Mug, What is a "VBScript executable"? (except some hacking where it is embedded in a VB.net wrapper or similar, I know of no such thing), and as for "outside of procedure scopes", assume readers have a brain and just happen not to have come across that term. Please explain (and not in "you are assumed to be a guru mind reader parlance" if that's OK :-). I suspect you mean you can write code in a "module" header like the original QB? Dec 17, 2017 at 1:16
-
@user1863152 hmm looks like it's missing a word. I meant "executable statements", i.e. VBScript code doesn't require to be scoped, like VB6 code does - in other words it's not true that VB6 can run any VBS code, at least not without modifications, however small they might need to be. Dec 17, 2017 at 1:20
VB is application development tool (like, desktops, web based application)
And VB script is scripting language, it can not independently developed application.