将 GUI 添加到 VBScript [英] Adding a GUI to VBScript

查看:33
本文介绍了将 GUI 添加到 VBScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在编写 vbs 脚本,但我需要用户与脚本进行交互.基本上我需要两个按钮和 4 个复选框(复选框不重要).

I'm currently working on a vbs script but I need user interaction with script. Basically I need two buttons and 4 checkboxes ( checkboxes isn't important).

提前致谢

推荐答案

VBScript 有对话框,只是不多,也没有复选框,你需要一个 COM 对象来做到这一点(并且有).我相信你知道 Messagebox,这里有一个鲜为人知的 Popup 的例子

VBScript has dialogs, only not many and no checkboxes, you would need a COM object to do so (and there are). I'm sure you know Messagebox and here an example of the less known Popup

Dim WshShell, BtnCode
Set WshShell = WScript.CreateObject("WScript.Shell")

BtnCode = WshShell.Popup("Do you feel alright?", 7, "Answer This Question:", 4 + 32)

Select Case BtnCode
   case 6      WScript.Echo "Glad to hear you feel alright."
   case 7      WScript.Echo "Hope you're feeling better soon."
   case -1     WScript.Echo "Is there anybody out there?"
End Select

然而,在 vbscript 中拥有更多对话框的最佳方式是使用 HTA.这里有一个例子

However, the best way to have more dialogs in vbscript is using HTA. Here an example

<HTML><HEAD>
   <HTA:APPLICATION
   ID = "oApp"
   APPLICATIONNAME = "Example"
   BORDER = "thick"
   CAPTION = "yes"
   ICON = "app.ico"
   SHOWINTASKBAR = "yes"
   SINGLEINSTANCE = "yes"
   SYSMENU = "yes"
   WINDOWSTATE = "normal"
   SCROLL = "yes"
   SCROLLFLAT = "yes"
   VERSION = "1.0"
   INNERBORDER = "yes"
   SELECTION = "no"
   MAXIMIZEBUTTON = "yes"
   MINIMIZEBUTTON = "yes"
   NAVIGABLE = "yes"
   CONTEXTMENU = "yes"
   BORDERSTYLE = "normal"
   >

   <SCRIPT language="vbscript">
   sub SimpleExeample()
     document.body.innerHTML = "<form name=myform><input type=checkbox name=chk1>Check me<br><br><button onclick='alert(myform.chk1.checked)'>Show if checked</button></form>"
   end sub
   </SCRIPT>

</HEAD>
<BODY onLoad="SimpleExeample()">
</BODY>
</HTML>

有一件事我同意 Cody,如果你开始编程,请选择另一种语言,vbscript 几乎已经死了.看一看 Ruby,一开始很容易上手,而且很有趣.这是一个使用鞋子作为 GUI 的 ruby​​ 脚本示例

In one thing i agree with Cody, vbscript is nearly dead, if you start programming choose another language. Take a look at Ruby, the start is easy to learn an it is FUN. Here an example of u ruby script using shoes as GUI

require 'green_shoes'
Shoes.app{
  button("Click me!"){alert("You clicked me.")}
}

由于我的 Ruby 替代方案引起了一些问题,这里有一种更传统的方式更接近 Vbscript 对同一示例的使用.上面的示例更多地用于函数式链式编程方式.

since my Ruby alternative rises some questions, here a more traditionel way closer to Vbscript uses of the same sample. The sample above is used more for a functional chained way of programming.

require 'green_shoes'
Shoes.app do
  button("Click me!") do
    alert("You clicked me.")
  end
end

这篇关于将 GUI 添加到 VBScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆