Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


ProgressBar (pure VBS)

 
Logged in as: Guest
arrSession:exec spGetSession 2,16,24746
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> Post a VBScript >> ProgressBar (pure VBS)
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 ProgressBar (pure VBS) - 8/11/2005 5:33:18 AM   
  Fredledingue


Posts: 326
Score: 0
Joined: 5/9/2005
From:
Status: offline
HI,
I would like to introduce you to a ProgressBar script I wrote but because it takes some explainantions, and because there are two versions + two sample scripts, I will split it into several posts.
________________________

Ok, First, the "readme":

How to

Copy-paste the lines from the samples.
I hope it won't be too difficult to find out where you can instert these lines into your script.

ProgressBarFast.vbs or ProgressBar.vbs , as well as ProgressBar.log must be included in the same directory as your script.

---------------

Files

ProgressBarFast.vbs is to use for fast process that last between 5 seconds to 5 minutes.

ProgressBar.vbs is to use for very slow process that can last several hours.

ProgressBar.log contains the datas needed by the progressbar script. your script must write a header (see sample) then "+1" for each item procesed at the end of this file.

_________________

Advantage:

1/ It's a purely textbox based progressbar. It doesn't require any dll installation and doesn't invoke heavy duty IE function or something.
It's fast and purely no-nonsens VBS.

2/ Modify and adapt the progressbar script as you please

3/ "ok" will make the taskbar disapear for a while then will come back after an intelligent period of time.

4/ "cancel" will stop the process without causing an error by leting an item half done.

-----------------

Downsides and limitations:

1/ This progressbar is not minimizable. It can be irritating to have it poping up all the time. In this case clic "ok".
However, in some case it can be useful to prevent user from using their computer during the process! :)

2/ "Cancel" won't be able to kill the process if the item being processed freezes, crashes or doesn't respond (in this case you will have to Ctr+Alt+Del).
It can stop only after the item is finished but can you copy-paste the code to terminate the script in several places in you main script.

3/ Design limited to the basic MsgBox. but we do VBS aren't we? ;)

< Message edited by Snipah -- 11/5/2005 6:47:04 PM >


_____________________________

Fred
 
 
Post #: 1
 
 RE: ProgressBar (pure VBS) - 11/3/2005 8:05:45 AM   
  Fredledingue


Posts: 326
Score: 0
Joined: 5/9/2005
From:
Status: offline
This new version allows you to stop your script by pressing the "cancel" button on the taskbar.



Code for ProgressBarFast.vbs
Note that's a second script file, separate from the main script, and that must be in the same directory as the main script.
____________________________________________


'--------set--------
Set fso = CreateObject("Scripting.fileSystemObject")
Set WshShell = WScript.CreateObject("WScript.Shell")
Title = "Progress"
'--------create nul file---------
'-----this file if exists, will tell the main script to continue.
'------This file contains no data. Only the existance of this file is important
fso.CreateTextFile "ok.nul", True
'--------read from file-----------
Set f = fso.GetFile("ProgressBar.log")
Set ts = f.OpenAsTextStream(1,0)
Execute ts.ReadAll
ts.Close
d = FormatNumber( Done / (sNum/100) +1 ,0,0,0,0)
Msg1 = String(d, "]") & String(100 - d, ".")
Msg2 = Done & "/" & sNum
Msg3 = "To stop the process clic ""Cancel"""
Do Until Done >= sNum
'---------this popup will refresh every 2 seconds
BtnCode = WshShell.Popup(Msg1 & VbCrlf & Msg2 & VbCrlf & Msg3, 2, Title, 1) '------to change the refresh speed: change the number after "Msg3,"
Select Case BtnCode
case 1 MsgBox "The progress bar will be back in one minutes.",,Title '------ok
WScript.Sleep 60000
case 2 MsgBox "The operation will be stopped once the current item is finished.",,Title
fso.GetFile("ok.nul").Delete '-----deleting the nul file to tell the main script to stop
wscript.quit
End Select
Set ts = f.OpenAsTextStream(1,0)
Execute ts.ReadAll
ts.Close
d = FormatNumber( Done / (sNum/100) +1 ,0,0,0,0)
If d <= 100 Then
Msg1 = String(d, "]") & String(100 - d, ".")
End If
Msg2 = Done & "/" & sNum
'-----------check if progressing--------
Done1 = Done2
Done2 = Done
If Done2 > Done1 Then
Idletime = 0
Else
Idletime = Idletime +1
If Idletime = 45 Then
WshShell.Popup "Program not responding!",, Title, 0 + 16
End If
End If
Loop


< Message edited by Fredledingue -- 11/3/2005 8:19:55 AM >


_____________________________

Fred
 
 
Post #: 2
 
 RE: ProgressBar (pure VBS) - 11/3/2005 8:40:46 AM   
  Fredledingue


Posts: 326
Score: 0
Joined: 5/9/2005
From:
Status: offline
Here is the sample script for ProgressBarFast.vbs
You will need to insert some the codes of this script into your main script. This sample script is just doing nothing except waiting
___________________


Set WshShell = WScript.CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
'---------number of items------------
sNum = 300
'------you will need to count how many items to process before. see (1)
'--------write to progressbar report---------
Set Progress = fso.OpenTextFile("ProgressBar.log", 2) '---ForWriting
Progress.WriteLine "sNum = " & sNum
Progress.WriteLine "Done = 0 _"
Progress.Write "+0"
WshShell.Run "ProgressBarFast.vbs"
WScript.Sleep 250
'----------------------------------------------------
For i=0 To sNum
'-------process the items here. see (2)
WScript.Sleep 50
'-------replace "WScript.Sleep 50 " by some operation here. see (3)
Progress.Write "+1"
'-------------stop script at user's request------------
'------by pressing the "cancel" button on the progressbar (the other script), the user
'------will stop this script here.
'------and the script of the progressbar will delete the "ok.nul" file
'-------if "ok.nul" has been deleted te script will not continue-----
If Fso.FileExists("ok.nul") = False Then
Progress.Close

'-----------re-write your termination/end-of-script codes here (or call a sub)

MsgBox "Operation aborted by user",,Title
wscript.quit
End If
'---------------------------------
Next

'-----------write your termination/end-of-script codes here (or call a sub)


'--------------------------------------------------
Progress.Close
MsgBox "ok",,"Test"
'------------end of script sample---------


(1) The number of items that the progressbar will report to be done. For example you want to process 300 text files, you will have to first know that there will be 300 files to process, then write sNum = 300.
If you don't know how many items to process, it will be useless but there are many easy ways to count. For example File.Count or a quick loop that will read each lines in text file etc

(2)The items will have to be processed in the For/Next loop. As the script know the exact number of items there should be no error such as "out of range" etc. For/Next can be replaced by Do/Loop or While/Wend if you prefer. I think it should work as well

(3) WScript.Sleep 50 is NOT necessary, PLEASE REMOVE IT in your script, I just wrote it for the demo. In place there should be your code processing the item. This code can be as long as you want.

< Message edited by Snipah -- 11/5/2005 6:50:47 PM >


_____________________________

Fred

(in reply to Fredledingue)
 
 
Post #: 3
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> Post a VBScript >> ProgressBar (pure VBS) Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts