vba VBS中的你好世界
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37906620/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Hello world in VBS
提问by IGRACH
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:
几天前我开始玩 VBScript,有一个问题让我很恼火。我试图测试简单的 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. I'm getting an error:
M:\hello world.vbs(6, 1) Microsoft VBScript compilation error: Expected statement
当我使用cscript "hello world.vbs", 从 cmd运行它时。我收到一个错误:
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.
当我将代码更改为 only 时:
MsgBox("Hello, World!") ' Display message on computer screen.代码正常运行。有一个弹出消息,没有错误。我使用的是 Win 7 SP1、Sublime text 3 并且我已经安装了 .Net 4.5;4.6.
I'm a bit noob to .VBS so please don't be harsh. Thank you xD.
我对 .VBS 有点菜鸟,所以请不要太苛刻。谢谢xD。
回答by Filburt
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 Moduleand a Mainfunction as an entry point.
您不需要将包含结构(如 aModule和Main函数)声明为入口点。
Since it looks like you tried to adopt from Visual Basic (for Applications) I recommend Visual Basic for Applications Features Not In VBScriptas a reference.
由于看起来您尝试采用 Visual Basic(用于应用程序),因此我建议将Visual Basic for Applications Features Not In VBScript作为参考。
回答by Sebastin Anthony
Use only this
只使用这个
Sub Main()
MsgBox("Hello, World!") ' Display message on computer screen.
End Sub
if you want to use with function
如果你想使用 with 函数
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

