Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hello world in VBS

I have start playing with VBScript a couple of days ago and there is a problem that is irritating me. I have tried to test simple hello world program:

Module Hello
  Sub Main()
      MsgBox("Hello, World!") ' Display message on computer screen.
  End Sub 
End Module

When I run it with cscript "hello world.vbs", from cmd. I'm getting an error: M:\hello world.vbs(6, 1) Microsoft VBScript compilation error: Expected statement

When I change code to only: MsgBox("Hello, World!") ' Display message on computer screen. Code is running normally. There is a popup message and there are no errors. I'm using Win 7 SP1, Sublime text 3 and I have installed .Net 4.5; 4.6.

I'm a bit noob to .VBS so please don't be harsh. Thank you xD.

like image 846
IGRACH Avatar asked Jun 19 '16 11:06

IGRACH


People also ask

What language is used in VBS?

Basically it is the combination of Visual Basic programming language and JavaScript language. VBScript was invented and maintained by Microsoft. It is used to develop dynamic web pages. It is much lighter compared to Visual Basic programming language but works as a scripting language like JavaScript.

What is WScript echo in VBScript?

You can use WScript. Echo to see exactly what VBScript passes out; if the string you see in the result of WScript. Echo works in a command-prompt window, it will work as the first argument for the Run method.

Can you run VBS in CMD?

If you want to execute a VBScript in the command prompt, you can use cscript.exe. See an example below. You can use Wscript. Echo in the VBScript in order to print information that will be displayed in the command prompt.


1 Answers

The entry point for VBScript is the global area at the top of the script file.

You do not need to declare a containing structure like a Module and a Main function as an entry point.

Since it looks like you tried to adopt from Visual Basic (for Applications) I recommend Visual Basic for Applications Features Not In VBScript as a reference.

like image 154
Filburt Avatar answered Sep 30 '22 08:09

Filburt