Search code examples
htmlvbscripthta

How to output result inside HTA window instead of a pop up message box?


I have a button in HTA file, it will search certain strings then output the result.(Thanks for @Ansgar Wiechers) I want to output the result in side of this HTA window instead of popping up a message box. The result will fill in the blank "YOU ARE IN _____ MODE"

How can I do it?

<html>
<head>
<title></title>
<HTA:APPLICATION
  APPLICATIONNAME=""
  ID=""
  VERSION="1.0"/>
</head>

<script language="VBScript">

Sub RUNCURRENTMODE
      Set xml = CreateObject("Msxml2.DOMDocument.6.0")
xml.async = False
xml.load "C:\aaa\settings.xml"

If xml.ParseError Then
  MsgBox xml.ParseError.Reason
  self.Close()  'or perhaps "Exit Sub"
End If

For Each n In xml.SelectNodes("//CSVName")
  Select Case n.Attributes.GetNamedItem("Value").Text
    Case "standard.csv"     : MsgBox "This is standard."
    Case "non-standard.csv" : MsgBox "This is non-standard."
    Case Else               : MsgBox "Unexpected value."
  End Select
Next
End Sub

</script>

<body bgcolor="buttonface">
<center>
<p><font face="verdana" color="red">YOU ARE CURRENTLY IN STANDARD CSV MODE</font></p>
<input id=runbutton  class="button" type="button" value="CURRENT MODE" name="db_button"  onClick="RUCURRENTMODE" style="width: 170px"><p>
</center>


</body>
</html>

Solution

  • Normally you'd put an element with an ID into the <body> section of the HTA, for instance a paragraph. Or a span, since you want to update only a portion of the text:

    <body>
    <p>You are in <span id="FOO"></span> mode</p>
    </body>
    

    and change the value of the element with that ID in your function:

    Select Case n.Attributes.GetNamedItem("Value").Text
      Case "standard.csv"     : FOO.innerText = "standard."
      Case "non-standard.csv" : FOO.innerText = "non-standard."
      Case Else               : MsgBox "Unexpected value."
    End Select