HTA Progress Blocks

This is an example of progress blocks to use in HTA applications (VBscript)
It works on the same principle as that of the Progress Bar for hta with the difference that it shows a serie of colored blocks, one per item.
The script will display a red block when the item has been processed with an error, a blue one when processed normaly, a green one for the one being processed and grey ones for those remaining.
Those who remember the old w98 defragmenter will know what I mean.
Discuss on
<title id="title">ProgressBar 2.1</title>
<script language="vbscript">

	'This is an example of progressbar
Public x,y, MyTitle, iTimerID, KeepGoing
ReDim PorgBarArray(1)

Sub Window_Onload
MyTitle = document.Title
End Sub

Sub Go
x=0   '--- x will be the number of item done.
y=350  '--- y will be the number of item to do.
Set fso = CreateObject("Scripting.FileSystemObject")
Set oof = fso.CreateTextFile("testpb.vbs", True)
oof.WriteLine "wscript.sleep WScript.Arguments(0)"  '---We'll run a sleep script so that 
			'we can see the progressbar going slowly
Set WshShell = CreateObject("WScript.Shell")

ReDim PorgBarArray(y+1)  '---Set an array where the content of the progressbar will be defined
	For i=1 To y
	PorgBarArray(i) = "g" '---Fill the array with "g", a square symbol in the Webdings font table
	Do Until x=y
	WshShell.Run "testpb.vbs 250",1,True  '----FOR TEST ONLY
		If x=4 Or x=11 Or x=17 Or x=20 Or x=29 Or x=30 Then '---Conditions to create a fake error
		PorgBarArray(x) = "<span style=""color:red"">g</span>" '---It will be shown in red
		PorgBarArray(x) = "g" '---normal
		End If
		If KeepGoing = False Or window.screenTop > 10000 Then '---"window.screenTop > 10000" prevents 
					'the loop for continuing when the window is closed
		PorgBarArray(x+1) = "</span>g"  '---end of blue span
		Exit Do
		PorgBarArray(x+1) = "</span><span style=""color:green"">g</span>"  '--- next to do is 
						'shown in green + end of blue span
		End If
PorgBarArray(y+1) = "</span>"  '---This makes the last block blue	
End Sub

Sub Progress(v)
	Select Case v
	Case 0  '---Stoping the progressbar activity---
		window.clearInterval(iTimerID)  '----Cancel the order to launch the Sub at the 500 milliseconds interval 
		iTimerID =""             '----Tells the program that iTimerID is nothing. 
					'Usefull to know if the progressbar is in activity or not.
		id("BtnGo").disabled = False       '----Allow the user to restart
		id("BtnCancel").disabled = True    '-----No need to press this button anymore
		id("BtnExit").disabled = False     '----Allow the user to exit the program
		Progress(2)            '----Update the progressbar one last time
		MsgBox "Operation finished.",,MyTitle
	Case 1  '---Starting the progressbar---
		id("ProgBarDone").innerHtml = Join(PorgBarArray)  '---Populate the progressbar with blocks the first time
		PorgBarArray(0) = "<span style=""color:blue"">" '---Give the "blue" tag to next done items
		iTimerID = window.setInterval("Progress(2)", 500)    '----- Launching the Sub Progress 
				'every 500 milliseconds with the variable 2
		id("BtnGo").disabled = True        '----No need to press the Go button twice
		id("BtnCancel").disabled = False   '---Allow the user to stop the process
		id("BtnExit").disabled = True      '----Forbid the user to close the program before it's over
		KeepGoing = True

	Case 2  '---Updating the progressbar---
		document.Title = FormatPercent(x/y, 0) & MyTitle  '---Add a nice percentage indication of the progrss 
						'in the title bar, also visible in the desktop taskbar
		id("ProgBarText").innerText = x & "/" & y  '----Shows the number of itmed done 
						'and the number of items to do
		id("ProgBarDone").innerHtml = Join(PorgBarArray)  '---Fill the Progress bar with the Array 
						'where the blocks are defined
	End Select
End Sub

Function id(o)
Set id = document.getElementById(o)
End Function

Sub Help
MsgBox "This is an example of progressbar in HTA written by Fredledingue.",,MyTitle
End Sub

<body bgcolor="GreenYellow">
<!-- Basic buttons -->
<input id="BtnGo"     type="button" value="Go"     onclick="Go">
<input id="BtnCancel" type="button" value="Cancel" onclick="KeepGoing=False" disabled="True">
<input id="BtnExit"   type="button" value="Exit"   onclick="window.close">
<input id="BtnHelp"   type="button" value="Help"   onclick="Help">
<!-- Progress bar -->
Done: <span id="ProgBarText">?</span><br>
<span id="ProgBarDone" style="font-family:Webdings; color:silver"></span>
<!-- Progress bar (End) -->


See also HTAsoft's homepage
 and Maxthon Plugins  and  Installed Files Checker  and W98SE Post uSP3 Updates