Adding a GUI to VBScript

前端 未结 3 901
太阳男子
太阳男子 2020-12-03 23:39

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

Thanks

3条回答
  •  隐瞒了意图╮
    2020-12-03 23:58

    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

    
       
    
       
    
    
    
    
    
    

    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
    

提交回复
热议问题