1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
| <html>
<head>
<title id="title">ProgressBar 2.1</title>
<HTA:APPLICATION ID="porgbar" APPLICATIONNAME="progbartest">
<script language="vbscript">
'---------------------------------
'This is an example of progressbar
'---------------------------------
Public x,y, MyTitle, iTimerID, KeepGoing
Sub Window_Onload
MyTitle = document.Title
id("ProgBarToDo").innerText = String(80, "_") & "|" '----Fills the progressbar with gray.
'You can hardcode it in the body html, but it's more flexible like this
window.ResizeTo 720, 200 '----Resizing to a better size for a progressbar
x=0 '--- x will be the number of item done.
y=35 '--- y will be the number of item to do.
End Sub
Sub Go
'---FOR TEST ONLY---
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
oof.Close
Set WshShell = CreateObject("WScript.Shell")
'----END OF TEST ONLY----
Progress(1)
Do Until x=y
x=x+1
WshShell.Run "testpb.vbs 250",1,True '----FOR TEST ONLY
If KeepGoing = False Or window.screenTop > 10000 Then '---"window.screenTop > 10000" prevents
'the loop for continuing when the window is closed
Exit Do
End If
Loop
Progress(0)
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---
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
Progress(2) '---- Once started we can update it already
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
d = Round( x / (y/80) ,0) '------Formula: 80 is the width of the progressbar
'in number of characters
id("ProgBarDone").innerText = String(d, "_") '----Draws the progressing blue line indicating what is done
If d<80 Then '----The bar is not full yet
id("ProgBarToDo").innerText = String(80-d, "_") & "|" '----Draws the remaining grey part of the progressbar
Else '----If the progressbar is full, just do this...
id("ProgBarToDo").innerText = "|" '---No grey part left at all
End If
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
</script>
</head>
<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">
<br>
<!-- Progress bar -->
Done: <span id="ProgBarText">?</span><br>
<span id="ProgBarDone" style="background-color:blue"></span>
<span id="ProgBarToDo" style="background-color:silver"></span>
<!-- Progress bar (End) -->
</body>
</html> |
Partager