Flashing message in an HTA

P

Paul Randall

"MikeB" <m.byerleyATVerizonDottieNettie> wrote in message






<html>
<HEAD>
<TITLE>This is the Application Caption</TITLE>
<HTA:APPLICATION ID="oApp"
APPLICATIONNAME="Splash Screen"
BORDER="thick"
MAXIMIZEBUTTON="yes"
MINIMIZEBUTTON="yes"
CAPTION="YES"
ICON=""
SHOWINTASKBAR="yes"
SINGLEINSTANCE="yes"
SYSMENU="yes"
WINDOWSTATE="normal">
<style type="text/css">
.textBlack {
color : #000000;}

.textRed {
color : #CC0000;

}

</style>

<SCRIPT type="text/javascript">
var bBlinkON = false;

function SwapColors(valIN)
{
if (valIN.className=='textBlack')
valIN.className='textRed';
else
valIN.className='textBlack';
return;

}

function Init()
{
var fSC = function (){
SwapColors(window.document.getElementById('spanToBlink'))};
var UpdateTime = window.setInterval(fSC,1000);}

function Terminate()
{
window.clearTimeout();
}

</SCRIPT>
</HEAD>

<body onload="Init(); return false;">

<div><span id="spanToBlink" class="textBlack">This is my blinking
Text!</span>

</div>

</body>

</html>

Thanks Mike! Your code works.

Now the question is, how do I insert your javascript code into the HTA
that I referred to:

http://www.microsoft.com/technet/scriptcenter/resources/qanda/jan08/hey0130.mspx

The resulting HTA needs to have both VBScript and javascript code.
What I'm looking for is the HTA to have a blank span initially; and
then when I click the button, the text of my choosing appears, and it
starts blinking in the manner that your javascript code commands it to
do.

Thanks!

- Dave

Hi, Dave
If you don't already have it, download the HTA HelpOMatic.hta from
here:
http://www.microsoft.com/downloads/results.aspx?pocId=&freetext=hta&DisplayLang=en

A basic HTA looks like this:
<html>
<head>
<title>Put your window title bar here</title>
<script language="vbscript">
'Putting this script here prepositions the window.
'Windowstate=Maximize would override this.
Const wdDlg = 600, htDlg = 380 ' dialog size
Const pxLeft = 100, pxTop = 100 ' positioning
window.ResizeTo wdDlg,htDlg
window.MoveTo pxLeft,pxTop
</SCRIPT>
<HTA:APPLICATION
ID="Put your ID here"
APPLICATIONNAME="Put your application name here"
SCROLL="yes"
SINGLEINSTANCE="no"
WINDOWSTATE=""</head>

<SCRIPT Language="VBScript">
</SCRIPT>
<SCRIPT Language="JScript">
</SCRIPT>
<body>

</body>
</html>

The script near the beginning is something I've picked up in the M$
scripting newsgroup -- By being before the <HTA: ... > element, it
positions and sizes the HTA window before it is desplayed.

You can sprinkle <script> ... </script> blocks essentially anywhere
between the <head> and </html> tags. Each script block can specify
the language it uses; other languages like Perl, Python, Ruby, Rex,
and others can be installed. One hta can use a mixture of all the
scripting languages you have installed. Placing all the scripts in
front of the <body> tag helps with readability

You probably already know that subroutines and functions can be
specified to run when certain events associated with some object
occur. For example, the HTML for a button can specify a subroutine
name and arguments to be passed when the button's OnClick event is
invoked. Besides specifying the language, the <script ...> tag can
specify an object and an event name; the script within this script
block will only be executed in response to this event. Details of the
<script > element syntax is here:
http://msdn2.microsoft.com/en-us/library/ms535892(VS.85).aspx#

Functions and subroutines within the <script> ... </script> blocks are
only executed when they are called. The same is true when the <script
....> tag indicates that it is for a specific event for a specific
object. All other script is executed as it is encountered. You might
call this script the main program, although it can be parts of many
<SCRIPT type="text/javascript">
var bBlinkON = false;

Variable bBlinkON is defined outside any function/sub, so it is a
global variable available immediately to any line of JScript executed
at a later time.

Some of the things you have to do are:
-copy the JScript blocks to some place ahead of your <body ... > tag.
-modify your <body ... > tag to set up event handlers.
-modify the script to use your span's ID.
-Add a button & click handler to modify the text in the span.

As demonstrated in the blinking code, you can get a reference to your
span with code like:
window.document.getElementById('spanToBlink')
As with most elements, this element has an innerhtml property which
you can change to any text you want.

If you find the HTA helpOMatic.hta handy, you can customize it --
adding selection items and HTML blocks and associated script blocks or
modifying the current ones to your liking.

-Paul Randall
 
E

ekkehard.horner

Paul Randall schrieb:
[...]
A basic HTA looks like this:
<html>
<head>
<title>Put your window title bar here</title>
<script language="vbscript">
'Putting this script here prepositions the window.
'Windowstate=Maximize would override this.
Const wdDlg = 600, htDlg = 380 ' dialog size
Const pxLeft = 100, pxTop = 100 ' positioning
window.ResizeTo wdDlg,htDlg
window.MoveTo pxLeft,pxTop
</SCRIPT>
<HTA:APPLICATION
ID="Put your ID here"
APPLICATIONNAME="Put your application name here"
SCROLL="yes"
SINGLEINSTANCE="no"
WINDOWSTATE=""

missing a closing >

wrong! no elements allowed between said:
<SCRIPT Language="VBScript">
</SCRIPT>
<SCRIPT Language="JScript">
</SCRIPT>

the above script elements should be moved before the said:
<body>
</body>
</html>
[...]
 
H

Highlander

Thanks Mike! Your code works.

Now the question is, how do I insert your javascript code into the HTA
that I referred to:

http://www.microsoft.com/technet/scriptcenter/resources/qanda/jan08/h...

The resulting HTA needs to have both VBScript and javascript code.
What I'm looking for is the HTA to have a blank span initially; and
then when I click the button, the text of my choosing appears, and it
starts blinking in the manner that your javascript code commands it to
do.

Thanks!

- Dave

Hi, Dave
If you don't already have it, download the HTA HelpOMatic.hta from
here:http://www.microsoft.com/downloads/results.aspx?pocId=&freetext=hta&D...

A basic HTA looks like this:
<html>
<head>
<title>Put your window title bar here</title>
<script language="vbscript">
'Putting this script here prepositions the window.
'Windowstate=Maximize would override this.
Const wdDlg = 600, htDlg = 380  ' dialog size
Const pxLeft = 100, pxTop = 100  ' positioning
  window.ResizeTo wdDlg,htDlg
  window.MoveTo pxLeft,pxTop
</SCRIPT>
<HTA:APPLICATION
     ID="Put your ID here"
     APPLICATIONNAME="Put your application name here"
     SCROLL="yes"
     SINGLEINSTANCE="no"
     WINDOWSTATE=""

</head>

<SCRIPT Language="VBScript">
</SCRIPT>
<SCRIPT Language="JScript">
</SCRIPT>
<body>

</body>
</html>

The script near the beginning is something I've picked up in the M$
scripting newsgroup -- By being before the <HTA: ... > element, it
positions and sizes the HTA window before it is desplayed.

You can sprinkle <script> ... </script> blocks essentially anywhere
between the <head> and </html> tags.  Each script block can specify
the language it uses; other languages like Perl, Python, Ruby, Rex,
and others can be installed.  One hta can use a mixture of all the
scripting languages you have installed.  Placing all the scripts in
front of the <body> tag helps with readability

You probably already know that subroutines and functions can be
specified to run when certain events associated with some object
occur.  For example, the HTML for a button can specify a subroutine
name and arguments to be passed when the button's OnClick event is
invoked.  Besides specifying the language, the <script ...> tag can
specify an object and an event name; the script within this script
block will only be executed in response to this event.  Details of the
<script > element syntax is here:http://msdn2.microsoft.com/en-us/library/ms535892(VS.85).aspx#

Functions and subroutines within the <script> ... </script> blocks are
only executed when they are called.  The same is true when the <script
...> tag indicates that it is for a specific event for a specific
object.  All other script is executed as it is encountered.  You might
call this script the main program, although it can be parts of many


Variable bBlinkON is defined outside any function/sub, so it is a
global variable available immediately to any line of JScript executed
at a later time.

Some of the things you have to do are:
-copy the JScript blocks to some place ahead of your <body ... > tag.
-modify your <body ... > tag to set up event handlers.
-modify the script to use your span's ID.
-Add a button & click handler to modify the text in the span.

As demonstrated in the blinking code, you can get a reference to your
span with code like:
window.document.getElementById('spanToBlink')
As with most elements, this element has an innerhtml property which
you can change to any text you want.

If you find the HTA helpOMatic.hta handy, you can customize it --  
adding selection items and HTML blocks and associated script blocks or
modifying the current ones to your liking.

-Paul Randall- Hide quoted text -

- Show quoted text -

Thanks for the detailed response Paul.

I already have a good deal of experience creating HTAs, but using
VBScript code only. I've got no experience working with javascript. So
when Paul came up with the blinking text solution in javascript,
that's where I'm a little fuzzy - how to incorporate the javascript
code into my HTA.

I had already created an HTA which combined Paul's javascript code and
my own VBscript code; and I've got it close to working the way I want
it to - but not quite:

<html>
<head>
<TITLE>This is the Application Caption</TITLE>
<HTA:APPLICATION ID="oApp"
APPLICATIONNAME="Application Name Here"
BORDER="thick"
MAXIMIZEBUTTON="yes"
MINIMIZEBUTTON="yes"
CAPTION="YES"
ICON=""
SHOWINTASKBAR="yes"
SINGLEINSTANCE="yes"
SYSMENU="yes"
WINDOWSTATE="normal">

<style type="text/css">
.textBlack {color : #000000;}
.textRed {color : #CC0000;}
</style>
</head>

<SCRIPT type="text/javascript">
var bBlinkON = false;
function SwapColors(valIN)
{if (valIN.className=='textBlack')
valIN.className='textRed';
else
valIN.className='textBlack';
return;}

function Init()
{var fSC = function (){
SwapColors(window.document.getElementById('spanToBlink'))};
var UpdateTime = window.setInterval(fSC,1000);}

function Terminate()
{window.clearTimeout();}
</SCRIPT>

<SCRIPT Language = "VBScript">
Sub DisplayText_OnClick
DataArea.InnerHTML = "Text of my choosing here."
End Sub
</SCRIPT>

<!--
<body onload="Init(); return false;">
-->
<body>
<div>
<input type="button" value="Blink Text" onclick="Init()">
<p>
<span id="spanToBlink" class="textBlack">This is my blinking Text!</
span>
</div>
<p>
<input name= "DisplayText" type="button" value="Display Text"><p>
<span id=DataArea></span>
</body>
</html>


If you notice in the VBScript subroutine 'DisplayText_OnClick', I'm
able to specify the text of my choosing:

DataArea.InnerHTML = "Text of my choosing here."

This is what I can't figure out how to do in the javascript function.

On the VBScript side, when I click the button 'DisplayText', text is
displayed in the span area; which was initially blank. I want the
javascript code to work the same way. In that when I click the button
'Blink Text', the span area, which was initially blank, will now
display blinking text.

Any suggestions would be greatly appreciated. Thanks!

- Dave
 
H

Highlander

Thanks for the detailed response Paul.

I already have a good deal of experience creating HTAs, but using
VBScript code only. I've got no experience working with javascript. So
when Paul came up with the blinking text solution in javascript,
that's where I'm a little fuzzy - how to incorporate the javascript
code into my HTA.

I had already created an HTA which combined Paul's javascript code and
my own VBscript code; and I've got it close to working the way I want
it to - but not quite:

<html>
<head>
  <TITLE>This is the Application Caption</TITLE>
  <HTA:APPLICATION ID="oApp"
    APPLICATIONNAME="Application Name Here"
    BORDER="thick"
    MAXIMIZEBUTTON="yes"
    MINIMIZEBUTTON="yes"
    CAPTION="YES"
    ICON=""
    SHOWINTASKBAR="yes"
    SINGLEINSTANCE="yes"
    SYSMENU="yes"
    WINDOWSTATE="normal">

<style type="text/css">
.textBlack {color : #000000;}
.textRed  {color : #CC0000;}
</style>
</head>

<SCRIPT type="text/javascript">
var bBlinkON = false;
 function SwapColors(valIN)
{if (valIN.className=='textBlack')
      valIN.className='textRed';
else
      valIN.className='textBlack';
return;}

 function Init()
{var fSC = function (){
SwapColors(window.document.getElementById('spanToBlink'))};
var UpdateTime = window.setInterval(fSC,1000);}

function Terminate()
  {window.clearTimeout();}
 </SCRIPT>

<SCRIPT Language = "VBScript">
 Sub DisplayText_OnClick
DataArea.InnerHTML = "Text of my choosing here."
 End Sub
</SCRIPT>

<!--
<body onload="Init(); return false;">
-->
<body>
<div>
<input type="button" value="Blink Text" onclick="Init()">
<p>
<span id="spanToBlink" class="textBlack">This is my blinking Text!</
span>
</div>
<p>
<input name= "DisplayText" type="button" value="Display Text"><p>
<span id=DataArea></span>
</body>
</html>

If you notice in the VBScript subroutine 'DisplayText_OnClick', I'm
able to specify the text of my choosing:

DataArea.InnerHTML = "Text of my choosing here."

This is what I can't figure out how to do in the javascript function.

On the VBScript side, when I click the button 'DisplayText', text is
displayed in the span area; which was initially blank. I want the
javascript code to work the same way. In that when I click the button
'Blink Text', the span area, which was initially blank, will now
display blinking text.

Any suggestions would be greatly appreciated. Thanks!

- Dave- Hide quoted text -

- Show quoted text -

...when Paul came up with the blinking text solution in javascript...

I meant to say MIKE, not Paul. MikeB posted the blinking text solution
in javascript earlier in this thread.
 
P

Paul Randall

I already have a good deal of experience creating HTAs, but using
VBScript code only. I've got no experience working with javascript. So
when Paul came up with the blinking text solution in javascript,
that's where I'm a little fuzzy - how to incorporate the javascript
code into my HTA.

I had already created an HTA which combined Paul's javascript code and
my own VBscript code; and I've got it close to working the way I want
it to - but not quite:

<html>
<head>
<TITLE>This is the Application Caption</TITLE>
<HTA:APPLICATION ID="oApp"
APPLICATIONNAME="Application Name Here"
BORDER="thick"
MAXIMIZEBUTTON="yes"
MINIMIZEBUTTON="yes"
CAPTION="YES"
ICON=""
SHOWINTASKBAR="yes"
SINGLEINSTANCE="yes"
SYSMENU="yes"
WINDOWSTATE="normal">

<style type="text/css">
..textBlack {color : #000000;}
..textRed {color : #CC0000;}
</style>
</head>

<SCRIPT type="text/javascript">
var bBlinkON = false;
function SwapColors(valIN)
{if (valIN.className=='textBlack')
valIN.className='textRed';
else
valIN.className='textBlack';
return;}

function Init()
{var fSC = function (){
SwapColors(window.document.getElementById('spanToBlink'))};
var UpdateTime = window.setInterval(fSC,1000);}

function Terminate()
{window.clearTimeout();}
</SCRIPT>

<SCRIPT Language = "VBScript">
Sub DisplayText_OnClick
DataArea.InnerHTML = "Text of my choosing here."
End Sub
</SCRIPT>

<!--
<body onload="Init(); return false;">
-->
<body>
<div>
<input type="button" value="Blink Text" onclick="Init()">
<p>
<span id="spanToBlink" class="textBlack">This is my blinking Text!</
span>
</div>
<p>
<input name= "DisplayText" type="button" value="Display Text"><p>
<span id=DataArea></span>
</body>
</html>


If you notice in the VBScript subroutine 'DisplayText_OnClick', I'm
able to specify the text of my choosing:

DataArea.InnerHTML = "Text of my choosing here."

This is what I can't figure out how to do in the javascript function.

On the VBScript side, when I click the button 'DisplayText', text is
displayed in the span area; which was initially blank. I want the
javascript code to work the same way. In that when I click the button
'Blink Text', the span area, which was initially blank, will now
display blinking text.

Any suggestions would be greatly appreciated. Thanks!

- Dave

I'm not good with JScript or styles. Hopefully someone else can help
you.

In theory, changing the contents of the span to an empty string should
eliminate the blinking text. VBScript can do that with:
DataArea.InnerHTML = "Text of my choosing here."
and
DataArea.InnerHTML = ""
As currently written, your script blinks all text in the specified
span and any text that may follow. I don't think that is what you
want.

I have a feeling that the sample script Mike gave you left something
out. I'm thinking the purpose of
var bBlinkON = false;
is to give you a variable that you can just toggle between True and
False in order to have the contents of the span blink or not.
 
P

Paul Randall

ekkehard.horner said:
ekkehard.horner said:
Paul Randall schrieb:
[...]
wrong! no elements allowed between </head> and </body>
wrong! no elements allowed between said:
Not my day, obviously!

It happens to everyone :)

Scripts can be placed almost anywhere in the main HTA elements:

<html>
<script language="vbscript">
MsgBox "Entered <html> element"
</script>

<head>
<script language="vbscript">
MsgBox "Entered <head> element"
</script>

<title>

<script language="vbscript">
MsgBox "Scripts don't work within the title element"
</script>

Title: Script placement within HTA

</title>

<HTA:APPLICATION
ID="oHTA"
APPLICATIONNAME="Put your application name here"
SCROLL="yes"
SINGLEINSTANCE="no"
WINDOWSTATE=""

<script language="vbscript">
MsgBox "Scripts are ignored in <HTA:> element"

</head>

<script language="vbscript">
MsgBox "Exited <head> element"
</script>

<body>

<script language="vbscript">
MsgBox "Entered <body> element"
</script>

<input id=Test1 class="button" type="button"
value="Test 1" name="Test1" onClick="Test1.vbs">
<br>

<script language="vbscript">
MsgBox "One button should now be displayed in the HTA window"
</script>

<input id=Test2 class="button" type="button"
value="Test 2" name="Test2" onClick="Test2.vbs">
<br>

<script language="vbscript">
MsgBox "Two buttons should now be displayed in the HTA " & _
"window. VBScript's message box is modal - it blocks " & _
"the use of controls in the HTA window, or even " & _
"repositioning the HTA window. It would be interesting " & _
"to see an expanded test HTA that mixes languages and " & _
"demonstrates ways to pass variables between languages and " & _
"access functions and subroutines of alien languages."
</script>

</body>

<script language="vbscript">
MsgBox "Exited <body> element"
</script>

</html>
 
E

ekkehard.horner

Paul Randall schrieb:
[...]

The statement
> Scripts can be placed almost anywhere in the main HTA elements:

and most of the samples are correct and valuable. But there is at
least one position, where <script> isn't allowed: between </head>
and <body>.

http://www.w3.org/TR/html4/struct/global.html#edef-HTML

To add something more productive:

<html>
<head>
<hta:application id = "search"
/>
<title>search</title>
<meta http-equiv = "content-type" content="text/html; charset=iso-8859-1"/>
<meta http-equiv = "content-script-type" content = "text/vbscript"/>
<style type = "text/css">
.stdBtt
{ width: 80;
}
.Meta
{ color: red;
}
</style>
<script language = "VBScript"
type = "text/vbscript"
'<![CDATA[

Option Explicit

''= globals
' ============================================================================
Dim gCursor : gCursor = Empty
Dim nCnt : nCnt = Empty

''= start searching
' ============================================================================
Sub doStart()
gCursor = document.body.style.cursor
nCnt = 0
pMsg.InnerTEXT = "Searching ... " & nCnt
document.body.style.cursor = "wait"
Worker
End Sub

''= do the work step by step
' ============================================================================
Sub Worker()
If nCnt >= 10 Then
pMsg.InnerTEXT = "Idle"
pMsg.Style.Color = "black"
document.body.style.cursor = gCursor
Else
nCnt = nCnt + 1
pMsg.InnerTEXT = "Searching ... " & nCnt
If 0 = (nCnt Mod 2) Then
pMsg.Style.Color = "blue"
Else
pMsg.Style.Color = "red"
End If
window.setTimeout "Worker", 500, "VBScript"
End If
End Sub

''= refreshes the HTA page, which includes re-running any Windows_Onload code
' ============================================================================
Sub reloadHTA()
location.reload True
End Sub

']]>
</script>
</head>
<body>
<hr />
<input id = "bttStart" class = "StdBtt" type = "BUTTON" value = "Start" onclick =
"doStart">
<hr />
<input class = "StdBtt Meta" type = "BUTTON" value = "reload" onclick = "reloadHTA">
<hr />
<p id = "pMsg">
Idle
</p>
</body>
</html>
 
P

Paul Randall

Thanks for the input, ekkehard.
I rather doubt that Microsoft intended the HTA structure requirements
to match the w3 standards for HTML.

My intent was to create an HTA that demonstrates what is/is not
allowed by M$, not what is/is not allowed by the HTML standard. It is
difficult to tell whether Microsoft's failure to enforce the standard
is a feature or a bug. Microsoft's documentation is typically so poor
that I often feel that trial and error is the only way explore a
product's capabilities. Much like a blind man trying to figure out
what an elephant is and how to use it ;-)

-Paul Randall

ekkehard.horner said:
Paul Randall schrieb:
[...]

The statement
Scripts can be placed almost anywhere in the main HTA elements:

and most of the samples are correct and valuable. But there is at
least one position, where <script> isn't allowed: between </head>
and <body>.

http://www.w3.org/TR/html4/struct/global.html#edef-HTML

To add something more productive:

<html>
<head>
<hta:application id = "search"
/>
<title>search</title>
<meta http-equiv = "content-type" content="text/html;
charset=iso-8859-1"/>
<meta http-equiv = "content-script-type" content =
"text/vbscript"/>
<style type = "text/css">
.stdBtt
{ width: 80;
}
.Meta
{ color: red;
}
</style>
<script language = "VBScript"
type = "text/vbscript"'<![CDATA[

Option Explicit

''= globals
'
============================================================================
Dim gCursor : gCursor = Empty
Dim nCnt : nCnt = Empty

''= start searching
'
============================================================================
Sub doStart()
gCursor = document.body.style.cursor
nCnt = 0
pMsg.InnerTEXT = "Searching ... " & nCnt
document.body.style.cursor = "wait"
Worker
End Sub

''= do the work step by step
'
============================================================================
Sub Worker()
If nCnt >= 10 Then
pMsg.InnerTEXT = "Idle"
pMsg.Style.Color = "black"
document.body.style.cursor = gCursor
Else
nCnt = nCnt + 1
pMsg.InnerTEXT = "Searching ... " & nCnt
If 0 = (nCnt Mod 2) Then
pMsg.Style.Color = "blue"
Else
pMsg.Style.Color = "red"
End If
window.setTimeout "Worker", 500, "VBScript"
End If
End Sub

''= refreshes the HTA page, which includes re-running any
Windows_Onload code
'
============================================================================
Sub reloadHTA()
location.reload True
End Sub

']]>
</script>
</head>
<body>
<hr />
<input id = "bttStart" class = "StdBtt" type = "BUTTON" value =
"Start" onclick = "doStart">
<hr />
<input class = "StdBtt Meta" type = "BUTTON" value = "reload"
onclick = "reloadHTA">
<hr />
<p id = "pMsg">
Idle
</p>
</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,265
Messages
2,571,069
Members
48,771
Latest member
ElysaD

Latest Threads

Top