Microsoft HTA/Using VBScript

From Computernewb Wiki
Jump to navigation Jump to search
< Microsoft HTA/Buttons and forms!Microsoft HTA/Version checking >


One of Microsoft HTA's most notable features is its ability to be used as an easy way to make a front end for VBScript scripts. You already know that you can embed JavaScript in HTA through the script element. However, you can change the scripting language used from JavaScript to VBScript using the language attribute in the script element. In order to use VBScript in a script element, just set the value of the language attribute to VBScript exactly. In order to call VBScript subroutines from buttons, just set the onclick attribute to the function's name. There is an example of the usage of VBScript below.

Language: HTA
<!DOCTYPE html>

<html>
  <head>
    <title>HTA Test Program</title>
    <HTA:APPLICATION
      APPLICATIONNAME = "HTA Test Program"
    />
    <script language="VBScript">
      Sub ButtonPressed
        x=MsgBox("Hello, world!", 0+64, "HTA Test Program")
      End Sub
    </script>
  </head>
  <body>
    <h1>Press the button to open a message box.</h1>
    <button onclick="ButtonPressed">Click me</button>
  </body>
</html>