vbscript弹消息命令_VBScript中一行上的多个命令

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弹消息命令

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在VBScript使用Edge浏览器生成动态成长的向日葵,可以按照以下步骤进行操作: 1. 打开记事本(Notepad),并复制以下代码: ``` Set objShell = CreateObject("WScript.Shell") Set objEdge = CreateObject("Microsoft.Edge.Application") objEdge.Navigate2 "about:blank" Do While objEdge.ReadyState <> 4 WScript.Sleep 100 Loop objEdge.Document.write "<html><body bgcolor='yellow'></body></html>" Set objSunflower = objEdge.Document.createElement("div") objSunflower.id = "sunflower" objSunflower.style.position = "absolute" objSunflower.style.width = "10px" objSunflower.style.height = "10px" objSunflower.style.background = "orange" objSunflower.style.borderRadius = "50%" objSunflower.style.bottom = "0px" objSunflower.style.left = "50%" objEdge.Document.body.appendChild(objSunflower) Do While True intHeight = objSunflower.offsetHeight intWidth = objSunflower.offsetWidth If intHeight > 300 Then Exit Do objNewSunflower = objSunflower.cloneNode(True) objNewSunflower.style.width = intWidth * 1.1 & "px" objNewSunflower.style.height = intHeight * 1.1 & "px" objNewSunflower.style.bottom = intHeight & "px" objNewSunflower.style.left = intWidth / 2 & "px" objEdge.Document.body.appendChild(objNewSunflower) Set objSunflower = objNewSunflower WScript.Sleep 100 Loop ``` 2. 将上述代码保存为一个.vbs文件。例如,将文件保存为“DynamicSunflower.vbs”。 3. 双击运行DynamicSunflower.vbs文件,即可看到一个动态成长的向日葵。 注意:在上面的代码,我们利用了Edge浏览器来绘制向日葵,因此需要保证计算机安装有Edge浏览器。同时,由于这里涉及到了操作浏览器的DOM元素,因此也需要允许VBScript操作Edge浏览器。如果计算机禁用了VBScript或Edge浏览器,可能无法正常运行以上代码。 现在,您就可以成功地在VBScript使用Edge浏览器生成一个动态成长的向日葵了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值