ProgressBar (pure VBS)

Author Message
Fredledingue

  • Total Posts : 572
  • Scores: 2
  • Reward points : 0
  • Joined: 5/9/2005
  • Location: Europe
  • Status: offline
ProgressBar (pure VBS) Thursday, August 11, 2005 6:33 AM (permalink)
0
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 on Saturday, November 05, 2005 7:47 PM>
Fred
 
#1
    Fredledingue

    • Total Posts : 572
    • Scores: 2
    • Reward points : 0
    • Joined: 5/9/2005
    • Location: Europe
    • Status: offline
    RE: ProgressBar (pure VBS) Thursday, November 03, 2005 9:05 AM (permalink)
    0
    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 on Thursday, November 03, 2005 9:19 AM>
    Fred
     
    #2
      Fredledingue

      • Total Posts : 572
      • Scores: 2
      • Reward points : 0
      • Joined: 5/9/2005
      • Location: Europe
      • Status: offline
      RE: ProgressBar (pure VBS) Thursday, November 03, 2005 9:40 AM (permalink)
      0
      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 on Saturday, November 05, 2005 7:50 PM>
      Fred
       
      #3
        morpheus83uk

        • Total Posts : 738
        • Scores: 0
        • Reward points : 0
        • Joined: 8/21/2006
        • Status: offline
        RE: ProgressBar (pure VBS) Monday, September 15, 2008 2:16 AM (permalink)
        0
        I have a question in regards to this....
         
        There does not seem to be any code for ProgressBar.vbs is there any reason for this?
         
        Many Thanks
         
        James

         
        #4
          Fredledingue

          • Total Posts : 572
          • Scores: 2
          • Reward points : 0
          • Joined: 5/9/2005
          • Location: Europe
          • Status: offline
          RE: ProgressBar (pure VBS) Monday, September 22, 2008 9:23 AM (permalink)
          0
          "ProgressBar.vbs"  is in fact "ProgressBarFast.vbs" (the first code sample). Sorry for the confusion.
          In fact "fast" was added because it updates faster than the original one.

          Use the second code sample as a test to launch  "ProgressBarFast.vbs".

          Note, this exapmle use a log file written constantly. That's old code.
          recently I found better and more convenient to write and read in the registry (passing the variable there - the total of item to do and the total of item done - just two numerical var: x and y).

           
          Note also that other and I did much cooler progress bars in hta. This one is either for fun or if you don't want to use hta under any circumstance.


          Fred
           
          #5
            Zoolix

            • Total Posts : 3
            • Scores: 0
            • Reward points : 0
            • Joined: 11/26/2010
            • Status: offline
            Re: RE: ProgressBar (pure VBS) Friday, November 26, 2010 2:17 PM (permalink)
            0
            Whenever i put this code into the program im using Notepad++ and save it. it comes up with an error. Whats wrong???
             
            #6
              Fredledingue

              • Total Posts : 572
              • Scores: 2
              • Reward points : 0
              • Joined: 5/9/2005
              • Location: Europe
              • Status: offline
              Re: RE: ProgressBar (pure VBS) Saturday, November 27, 2010 2:50 AM (permalink)
              0
              I don't know. It's a Notepad++ issue.
              Fred
               
              #7

                Online Bookmarks Sharing: Share/Bookmark

                Jump to:

                Current active users

                There are 0 members and 1 guests.

                Icon Legend and Permission

                • 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
                • Read Message
                • Post New Thread
                • Reply to message
                • Post New Poll
                • Submit Vote
                • Post reward post
                • Delete my own posts
                • Delete my own threads
                • Rate post

                2000-2012 ASPPlayground.NET Forum Version 3.9