Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Method Popup in HTA didn't work ?

Status
Not open for further replies.

crackoo

Programmer
Feb 17, 2011
132
TN
Hi
i wonder why the Method Popup didn't work in a HTA, but in Vbscript works!
exemple : i want to perform a message Box waiting for 7 seconds and it close by it self if there is no intervention by the User:

VBS
Code:
Sub Popup()
Dim WshShell, BtnCode
Set WshShell = WScript.CreateObject("WScript.Shell")
 
BtnCode = WshShell.Popup("Comment allez-vous ?", 7, "Répondez à cette Question:", 4 + 32)
 
Select Case BtnCode
   case 6      WScript.Echo "Je suis ravie d'apprendre que vous allez bien."
   case 7      WScript.Echo "J'espère que vous irez mieux."
   case -1     WScript.Echo "Y-a-t-il quelqu'un ?"
End Select
End Sub
Call Popup

HTA
Code:
<html>
<head>
<title>Question</title>
<HTA:APPLICATION 
APPLICATIONNAME="Question"
SCROLL="yes"
SINGLEINSTANCE="yes"
WINDOWSTATE="normal"
>
<script language="VBScript">
Sub Popup()
Dim WshShell, BtnCode
Set WshShell = CreateObject("WScript.Shell")
 
BtnCode = WshShell.Popup("Comment allez-vous ?", 7, "Répondez à cette Question:", 4 + 32)
 
Select Case BtnCode
   case 6      WScript.Echo "Je suis ravie d'apprendre que vous allez bien."
   case 7      WScript.Echo "J'espère que vous irez mieux."
   case -1     WScript.Echo "Y-a-t-il quelqu'un ?"
End Select
End Sub
</script>
</head>
<body>
<input type="button" value="Question" name="run_button"  onClick="Popup"><p> 
</body>
</html>

So in HTA the message Box freezes and don't close by it self why ?
 
You need colons after the Case conditions, and you can't use wscript.echo if you are running your code in an HTA.

Try:
Code:
Select Case BtnCode
   case 6: Msgbox "Je suis ravie d'apprendre que vous allez bien."
   case 7: Msgbox WScript.Echo "J'espère que vous irez mieux."
   case -1: Msgbox WScript.Echo "Y-a-t-il quelqu'un ?"
End Select
 
I think the problem come that WScript objects are not supported in HTA.
So to bypass this limitation, i used this trick : generate a temporary vbscript file and execute it like this :
Code:
<html>
<head>
<title>Question</title>
<HTA:APPLICATION
APPLICATIONNAME="Question"
SCROLL="yes"
SINGLEINSTANCE="yes"
WINDOWSTATE="normal"
>
<script language="VBScript">
Sub Popup(Msg,Wait,Title)
 Set fso = CreateObject("Scripting.FileSystemObject")
 Set ws  = CreateObject("WScript.Shell")
 Dim tempFolder : Set tempFolder = fso.GetSpecialFolder(2)
 Dim tempName : tempName = "Popup.vbs"
  Set objOutputFile = fso.CreateTextFile(tempFolder&"\"&tempName, True)
  objOutputFile.Writeline "Set WshShell = CreateObject(""WScript.Shell"")"
  objOutputFile.WriteLine "BtnCode = WshShell.Popup("&qq(Msg)&","&qq(wait)&","&qq(Title)&", 4 + 32)"
  objOutputFile.WriteLine "Select Case BtnCode"
  objOutputFile.WriteLine "case 6      MsgBox ""Je suis ravie d'apprendre que vous allez bien !"" ,64,""Je suis ravie d'apprendre que vous allez bien !"""
  objOutputFile.WriteLine "case 7      MsgBox ""J'espère que vous irez mieux !"",64,""J'espère que vous irez mieux !"" "
  objOutputFile.WriteLine "case -1     MsgBox ""Y-a-t-il quelqu'un ?"",vbQuestion,""Y-a-t-il quelqu'un ?"" "
  objOutputFile.WriteLine "End Select"
  objOutputFile.Close
  ws.Run tempFolder&"\"&tempName
End Sub
 
Function qq(strIn)
    qq = Chr(34) & strIn & Chr(34)
End Function
</script>
</head>
<body>
<input type="button" value="Question" name="run_button"  onClick="Popup 'Comment allez-vous ?','5','Répondez à cette Question'"><p>
</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top