vbscript弹消息命令
Unlike scripting languages such as C# where a semi-colon is used to indicate the end of a command, Microsoft's VBScript language relies on line breaks to determine when a command begins and ends. As you can imagine, this quickly results in messy code, with declarations for variables, and then actually setting those variables, using up two lines, like the below.
与C#等脚本语言(其中使用分号指示命令的结束)不同,Microsoft的VBScript语言依靠换行符来确定命令的开始和结束时间。 可以想象,这很快导致代码混乱,带有变量的声明,然后像下面这样用两行来实际设置这些变量。
Dim myVariable
Set myVariable = Server.CreateObject("MyObject")
Dim myString
myString = Request.ServerVariables("name")
Dim myInt
myInt = 44-6
Fortunately, there is help at hand. A little known trick to many scripting in VBS is the power of the colon - this simple character enables you to place multiple commands on a single line, replacing the location where you would place a line break with a colon.
幸运的是,这里有帮助。 VBS中许多脚本的一个鲜为人知的技巧是冒号的功能-这个简单的字符使您可以在一行上放置多个命令,而用冒号代替放置换行符的位置。
Using this trick, my code above now looks like:
使用此技巧,上面的代码现在看起来像:
Dim myVariable: Set myVariable = Server.CreateObject("MyObject")
Dim myString: myString = Request.ServerVariables("name")
Dim myInt: myInt = 44-6
As you can see, this code is a lot cleaner; the colon character has been used to replace the line break between a variable declaration and setting that variable's value, enabling easier reading of code for both yourself and future developers.
如您所见,此代码更加简洁。 冒号字符已用于替换变量声明和设置该变量的值之间的换行符,从而使您自己和将来的开发人员都可以更轻松地阅读代码。
-Matt
-马特
翻译自: https://www.experts-exchange.com/articles/276/Multiple-Commands-on-a-Single-Line-in-VBScript.html
vbscript弹消息命令