Welcome !
         

 ProgressBar Classic [HTA] (Level = easy)

Author Message
Fredledingue

  • Total Posts : 585
  • Scores: -5
  • Reward points : 0
  • Joined: 5/9/2005
  • Location: Europe
  • Status: offline
ProgressBar Classic [HTA] (Level = easy) Wednesday, May 30, 2007 12:44 PM (permalink)
0
Two version for this ProgressBar:
 
1/ for small number of items to proceed (less than 50).
The lenght (or number of steps) of the bar is proportional to the number of items
 
2/ for large numbers of items (more than 50)
The lenght of the bar is 50.
---
 
- Displays percents in the taskbar and the caption
 
- Diplay numbers of done items and the total.
 
- "classic" because of the greyish background, of course you can change the colors: white will make it Windows 3.1 style, blue and yellow: BSOD style etc)
 
---
To use them in a useful manner, you will have to figure out how to feed the "x" variable to the progress bar. You can either include the prgressbar code into an hta application (progress shown on the main window) or make it read a file generated by the main scrit with the datas needed for the progressbar.
This code can be easily modified to add extra infos, colors, them, pictures etc
 
---
 
1/ for small number of items to proceed (less than 50).
The lenght (or number of steps) of the bar is proportional to the number of items
 
 <html>
 <head>
 <title id="title">Zzzzz</title>
 <HTA:APPLICATION 
     ID="ProgressBar"
     APPLICATIONNAME="ProgressBar"
     SCROLL="no"
     MAXIMIZEBUTTON="no"
     />
 <SCRIPT Language="VBScript">
 
 Public x, y, MyTitle
 
 Sub Window_Onload
 window.resizeTo 436,116
 y=5
 MyTitle = " _ Zzzz"
 window.setInterval "Progress", 150
 End Sub
  
 Sub Progress
  x=x+1
  document.Title = FormatPercent(x/y, 0) & MyTitle
  document.all.ProgBarText.innerText = x & "/" & y
  document.all.ProgBarDone.innerText = String(x, "_")
  document.all.ProgBarToDo.innerText = String(y-x, "_") & "|"
   If x=y Then
   document.all.ProgBarToDo.innerText = ""
   MsgBox "ok"
   window.close
   End If
 End Sub
 
 </SCRIPT>
 </head>
 <body bgcolor="#D7D7D7">
 <span id="ProgBarText"></span><br>
 <span id="ProgBarDone" style="background-color: #3399FF"></span>
 <font color="#FFFFFF">
 <span id="ProgBarToDo"style="background-color: #C0C0C0"></span>
 </font>
 </body>
 </html>
 
 

 
 
2/ for large numbers of items (more than 50)
The lenght of the bar is 50.
 
 <html>
 <head>
 <title id="title">Zzzzz</title>
 <HTA:APPLICATION 
     ID="ProgressBar"
     APPLICATIONNAME="ProgressBar"
     SCROLL="no"
     MAXIMIZEBUTTON="no"
     />
 <SCRIPT Language="VBScript">
 
 Public w,x,y, MyTitle 
 '-- w: bar width, x: done items, y: remaining items
 
 Sub Window_Onload
 window.resizeTo 440,116
 w=50
 y=1352
 MyTitle = " _ Zzzz"
 window.setInterval "Progress", 150
 End Sub
  
 Sub Progress
  x=x+27
  d = Round( x / (y/w) +1  ,0)
  document.Title = FormatPercent(x/y, 0) & MyTitle
  document.all.ProgBarText.innerText = x & "/" & y
  document.all.ProgBarDone.innerText = String(d, "_")
   If d<w Then
   document.all.ProgBarToDo.innerText = String(w-d, "_") & "|"
   Else
   document.all.ProgBarToDo.innerText = "|"
   End If
   If x>=y Then
   document.all.ProgBarToDo.innerText = ""
   MsgBox "ok"
   window.close
   End If
 End Sub
 
 </SCRIPT>
 </head>
 <body bgcolor="#D7D7D7">
 <span id="ProgBarText"></span><br>
 <span id="ProgBarDone" style="background-color: #3399FF"></span>
 <font color="#FFFFFF">
 <span id="ProgBarToDo"style="background-color: #C0C0C0"></span>
 </font>
 </body>
 </html>
 
 

Fred
 
#1
    Fredledingue

    • Total Posts : 585
    • Scores: -5
    • Reward points : 0
    • Joined: 5/9/2005
    • Location: Europe
    • Status: offline
    RE: ProgressBar Classic [HTA] (Level = easy) Monday, March 09, 2009 1:27 PM (permalink)
    0
    Here is my last version, complete, fully commented, and usable as is.

    Just insert your vbScript in it and it will work with a progress bar.

    This example shows how to work with files. It can work with other things of course, such as arrays.
    It also includes an example of "Sleep" in hta (two in one!)

    Just for the test, save this code under "sleeper.vbs", you don't need it for the progressbar itself.

    wscript.sleep WScript.Arguments(0)

    Then save this code under "progressbar.hta" and start it. The code looks big but once you remove all the comments it's much smaller!

    [/align][align=left]<html>
     <head>
     <title id="title">ProgressBar 2.0</title>
     <HTA:APPLICATION ID="porgbar" APPLICATIONNAME="progbartest">
     <SCRIPT Language="VBScript">
     '
     '-----------------------------------------------------------
     'This is an example of progressbar
     'To run this text you will need to create "sleeper.vbs":
     'Open Notepad and type (that's only one line):
     '                         wscript.sleep WScript.Arguments(0)
     'Then save under "sleeper.vbs" in the same folder as this application
     'It shows how it can be applied on file operations.
     'Of course it can be applied on other tings like lines in a text and so on.
     'Line of code marked '----FOR TEST can be deleted or modified when
     'you use it for your own application.
     'All other codes must stay.
     '-----------------------------------------------------------
     '
     Public x,y, MyTitle, iTimerID, KeepGoing
     '
     Sub Window_Onload
     MyTitle = document.Title
     document.all.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 bteer size for a progressbar
     x=0       '--- x will be the number of item done.
     y=0       '--- y will be the number of item to do. It will be defined later when the test is started
     End Sub
     '
     Sub Go
     KeepGoing=True  '---This is switch for stopping the test by pressing the cancel button or upon other events or conditions
     '-----TEST We will review all files in windows directory. ------
     Set WSHell=CreateObject("WScript.Shell")
     Set fso = CreateObject("Scripting.FileSystemObject")
     Set Folder = fso.getfolder("C:\Windows")
       For Each file in folder.files
       y=y+1         '--- Counting the number files for the progress bar
       Next
     '-----end of code FOR TEST------
     Progress(1)       '----(1)  means that we start the progress bar (see Sub Progress)
       For Each file in folder.files        '----FOR TEST: We have counted how many files in the folder, now we will do something with them
          If KeepGoing=False Then          '---It means we want to stop it
          Exit For                 '----and we jump to the line with Progress(0)
         End If
       WShell.Run "sleeper.vbs 250",1,True      '----FOR TEST: we run a sleep script so that we can see the progressbar going slowly
       x=x+1         '----Incrementing x for the progress bar.
       Next          '----FOR TEST
     Progress(0)       '----(0)  means that we stop the progress bar (see Sub Progress)
     End Sub
     '
     Sub Progress(var)
     Select Case var
     '
     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.
     document.form.BtnGo.disabled = False       '----Allow the user to restart
     document.form.BtnExit.disabled = False     '----Allow the user to exit the program
     document.form.BtnCancel.disabled = True    '-----No need to press this button anymore
     KeepGoing=False        '----Make sure the switch is off so that the loop stops
     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
     document.form.BtnExit.disabled = True      '----Forbid the user to close the program before it's over
     document.form.BtnGo.disabled = True        '----No need to press the Go button twice
     document.form.BtnCancel.disabled = False   '---Allow the user to stop the process
     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
     document.all.ProgBarText.innerHTML = file.path & "<br><b>" & x & "/" & y & "</b>"  '----Shows the number of items done and the number of items to do (+shows the file path)
     d = Round( x / (y/80) ,0)                 '------Formula: 80 is the width of the progressbar in number of characters
     document.all.ProgBarDone.innerText = String(d, "_")       '----Draws the progressing blue line indicating what is done
        If d<80 Then       '----The bar is not full yet
         document.all.ProgBarToDo.innerText = String(80-d, "_") & "|"  '----Draws the remaining grey part of the progressbar
         Else               '----If the progressbar is full, just do this...
         document.all.ProgBarToDo.innerText = "|"      '---No grey part left at all
         End If
      '
     End Select
     End Sub
     '
     Sub Help    '----FOR TEST
     MsgBox "This is an example of progressbar in HTA written by Fredledingue.",,MyTitle     '----FOR TEST
     End Sub     '----FOR TEST
     '
     </SCRIPT>
     '
     </head>
     <body bgcolor="#E5E5E5">
     '
     <FORM NAME="form">
     <!-- Basic buttons -->
     <INPUT NAME="BtnGo" TYPE="BUTTON" VALUE="Go" onclick="Go">
     <INPUT NAME="BtnCancel" TYPE="BUTTON" VALUE="Cancel" onclick="KeepGoing=False" disabled="True">
     <INPUT NAME="BtnHelp" TYPE="BUTTON" VALUE="Help" onclick="Help">
     <INPUT NAME="BtnExit" type="button" VALUE="Exit" onclick="window.close">
     <br>
     </FORM>
     '
     <!-- Progress bar (Text part) -->
     Done: <b><span id="ProgBarText">?</span></b><br>
     <!-- Progress bar (Graphic part) -->
     <span id="ProgBarDone" style="background-color: #3399FF"></span>
     <font color="#FFFFFF">
     <span id="ProgBarToDo"style="background-color: #C0C0C0"></span>
     <!-- Progress bar (End) -->
     '
     </font>
     </body>
     </html>[/align][align=left]
    <message edited by Fredledingue on Wednesday, June 17, 2009 10:43 AM>
    Fred
     
    #2
      NssB

      • Total Posts : 31
      • Scores: 0
      • Reward points : 0
      • Joined: 6/26/2006
      • Status: offline
      RE: ProgressBar Classic [HTA] (Level = easy) Tuesday, April 07, 2009 2:47 AM (permalink)
      0
      Nice work. However you could save a lot of trouble by implementing the OS activeX progress bar. I run multiple instances in my projects fairly easily. Granted there are not many customisation options, but if all you want is a bar, its a good start :)


      NssB
      Its all about the code!
       
      #3
        ..::Ryan::..

        • Total Posts : 108
        • Scores: 0
        • Reward points : 0
        • Joined: 3/23/2009
        • Status: offline
        RE: ProgressBar Classic [HTA] (Level = easy) Wednesday, May 20, 2009 12:51 AM (permalink)
        0
        I get a runtime error when I try to run it
         
        #4
          Fredledingue

          • Total Posts : 585
          • Scores: -5
          • Reward points : 0
          • Joined: 5/9/2005
          • Location: Europe
          • Status: offline
          RE: ProgressBar Classic [HTA] (Level = easy) Sunday, June 14, 2009 11:40 PM (permalink)
          0
          In fact this progressbar is not a pop up, it's a complement to your hta interface.
          You can use it as a pop up but it's best used within an existing hta console.
           
          Finaly it's all but classic. It's the progressbar with unlimited configuration. You can add buttons, change colors etc.
          And I wouldn't say it's very easy. But I can't change the thread title anymore.
           
          Ryan,
          Perhaps you forgot to create sleep.vbs.
          It's needed only to run the test. It's not needed for real use.
          Fred
           
          #5
            Fredledingue

            • Total Posts : 585
            • Scores: -5
            • Reward points : 0
            • Joined: 5/9/2005
            • Location: Europe
            • Status: offline
            RE: ProgressBar Classic [HTA] (Level = easy) Wednesday, June 17, 2009 10:29 AM (permalink)
            0
            I just modified the formula (code above updated):

            d = Round( x / (y/80) ,0)
             
            +I updated the code above so that it display the file path of the file being processed.
             
            Note:
            If you are processing an array starting with 0 (and x=0 when processing  the first item in the array) and y the number of cells in your array, the formula is:

            id("ProgBarText0").innerText = x+1 & "/" & y+1
            d = Round( (x+1) / ((y+1)/80)  ,0)

             
            So that when YouArray(0) has been processed, it already shows 1 on the counter and the blue line starts growing.
            It's important when working with small numbers.
             
            Atention:
            This website is adding in the code twice: 
            [/align][align=left]
             

            There is no way I can avoid that. Please remove it after copy-pasting the code.
            <message edited by Fredledingue on Wednesday, June 17, 2009 10:47 AM>
            Fred
             
            #6
              TomRiddle

              • Total Posts : 636
              • Scores: 12
              • Reward points : 0
              • Joined: 2/7/2008
              • Location: Australia
              • Status: offline
              RE: ProgressBar Classic [HTA] (Level = easy) Tuesday, June 23, 2009 1:22 AM (permalink)
              0
              Cool code Fred,

              This bit file.path & is causing an error in your script for me, but don't worry about it if you can't reproduce it.

              Also I have found using Firefox posting in this forum much better, because your code does not get screwed up and has the added benefit of spell check.

              Not pushing Firefox or anything but it is useful having an alternative browser for certain things.

              Cheers
               
              #7
                Fredledingue

                • Total Posts : 585
                • Scores: -5
                • Reward points : 0
                • Joined: 5/9/2005
                • Location: Europe
                • Status: offline
                RE: ProgressBar Classic [HTA] (Level = easy) Tuesday, June 23, 2009 7:59 AM (permalink)
                0
                file.path &
                 
                So how do you find a file path on your machine???
                 
                About FF, yes it's good to have an alternative but IMO this is more a problem sever side (asp).
                Thought I faced this problem only here.
                Fred
                 
                #8
                  TomRiddle

                  • Total Posts : 636
                  • Scores: 12
                  • Reward points : 0
                  • Joined: 2/7/2008
                  • Location: Australia
                  • Status: offline
                  RE: ProgressBar Classic [HTA] (Level = easy) Tuesday, June 23, 2009 3:03 PM (permalink)
                  0

                  ORIGINAL: Fredledingue

                  file.path &
                   
                  So how do you find a file path on your machine???

                   
                  FSO or WMI sorry writing new code is easier than debugging, anyway this part of the code is not neccessary to the progressbar itself.
                   
                  #9
                    dazlak

                    • Total Posts : 10
                    • Scores: 0
                    • Reward points : 0
                    • Joined: 11/9/2009
                    • Status: offline
                    Re: RE: ProgressBar Classic [HTA] (Level = easy) Monday, November 09, 2009 1:55 PM (permalink)
                    0
                    nice code. thank you
                    by removing file.path & , script runs with no problem
                     
                    #10
                      Fredledingue

                      • Total Posts : 585
                      • Scores: -5
                      • Reward points : 0
                      • Joined: 5/9/2005
                      • Location: Europe
                      • Status: offline
                      Re: RE: ProgressBar Classic [HTA] (Level = easy) Saturday, November 20, 2010 3:02 AM (permalink)
                      0
                      This is the real last version of the ProgressBar code sample: http://www.htasoft.com/progressbar_hta.htm
                      This test version should be more reliable than any previous ones, more complete, more standard and easier to understand.
                      This version makes use of TNO's Function id(o) which make the code considerably smaller and easier to read (once you know what this function means).
                      (I put the code on my website because it displays better than here, and because I can't re-edit old messages. You will also appreciate the "Remove quotes" button. 8) )
                      Fred
                       
                      #11
                        Online Bookmarks Sharing: Share/Bookmark

                        Jump to:

                        Current active users

                        There are 0 members and 3 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-2017 ASPPlayground.NET Forum Version 3.9