简体   繁体   English

VBS中的Hello世界

[英]Hello world in VBS

I have start playing with VBScript a couple of days ago and there is a problem that is irritating me. 我几天前开始玩VBScript了,有一个问题让我感到恼火。 I have tried to test simple hello world program: 我试过测试简单的hello world程序:

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. 当我使用cscript "hello world.vbs"运行它时,来自cmd。 I'm getting an error: M:\\hello world.vbs(6, 1) Microsoft VBScript compilation error: Expected statement 我收到一个错误: 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. 当我将代码更改为: 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; 我使用的是Win 7 SP1,Sublime text 3,我安装了.Net 4.5; 4.6. 4.6。

I'm a bit noob to .VBS so please don't be harsh. 我对.VBS有点小说,所以请不要苛刻。 Thank you xD. 谢谢xD。

The entry point for VBScript is the global area at the top of the script file. VBScript的入口点是脚本文件顶部的全局区域。

You do not need to declare a containing structure like a Module and a Main function as an entry point. 您不需要将类似ModuleMain函数的包含结构声明为入口点。

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. 因为看起来你试图从Visual Basic(对于应用程序)采用,我推荐Visual Basic for Applications功能不在VBScript中作为参考。

Use only this 仅使用此功能

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

if you want to use with function 如果你想使用功能

function Main()
         MsgBox("Hello, World!") ' Display message on computer screen.
end function

call with either the function or subroutine name in both cases to invoke it. 在两种情况下调用函数或子例程名称来调用它。

call Main

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM