Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a GUI to VBScript

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).

like image 768
Deniz da King Avatar asked Apr 17 '13 05:04

Deniz da King


1 Answers

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

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>

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.")}
}

EDIT: 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
like image 180
peter Avatar answered Oct 13 '22 01:10

peter