MISC.‎ > ‎

Progress Bar

This is a nice implementation of a Progress Bar

I found this Scrip somewhere on the Internet, Fixed it a little and here it is.
This script Uses a Progress bar Class that can receive 
a Title for the Progress bar
a Progress Text
and of course a Progress Status Update

Download the Script
 Class ProgressBar
    Private m_PercentComplete
    Private m_CurrentStep
    Private m_ProgressBar
    Private m_Title
    Private m_Text
    Private m_StatusBarText
 
    'Initialize defaults
    Private Sub ProgessBar_Initialize
        m_PercentComplete = 0
        m_CurrentStep = 0
        m_Title = "Progress"
        m_Text = ""
    End Sub
 
    Public Function SetTitle(pTitle)
        m_Title = pTitle
    End Function
 
    Public Function SetText(pText)
        m_Text = pText
    End Function
 
    Public Function Update(percentComplete)
        m_PercentComplete = percentComplete
        UpdateProgressBar()
    End Function
 
    Public Function Show()
  Const navOpenInNewWindow = 1
   Const navNoHistory = 2
   Const navNoReadFromCache = 4
   Const navNoWriteToCache = 8
   Const navAllowAutosearch = 16
   Const navBrowserBar = 32
   Const navHyperlink = 64
   Const navEnforceRestricted = 128
   Const navNewWindowsManaged = 256
   Const navUntrustedForDownload = 512
   Const navTrustedForActiveX = 1024
   Const navOpenInNewTab = 2048
   Const navOpenInBackgroundTab = 4096
   Const navKeepWordWheelText = 8192
   Const navVirtualTab = 16384
   Const navBlockRedirectsXDomain = 32768
   Const navOpenNewForegroundTab = 65536

        Set m_ProgressBar = CreateObject("InternetExplorer.Application")
        ' Set The Window Properties
        m_ProgressBar.Navigate2 "about:", navNoHistory+navBrowserBar
        m_ProgressBar.width = 315
        m_ProgressBar.height = 40
        m_ProgressBar.toolbar = False
        m_ProgressBar.menubar = False
        m_ProgressBar.statusbar = False
        m_ProgressBar.visible = True
        m_ProgressBar.Resizable = False
        ' Write The Text Code in the File
        With m_ProgressBar.Document
         .Write "<html>"
         .Write "  <body Scroll=no style='margin:0px;padding:0px;'>"
         ' The Title Text
         .Write "    <div style='text-align:center;'>"
         .Write "      <span name='pc' id='pc'>0</span>"
         .Write "    </div>"
         ' The Status Bar
         .Write "    <div id='statusbar' name='statusbar' style='border:1px solid blue;line-height:10px;height:10px;color:blue;'></div>"
         ' The Progress Text
         .Write "    <div style='text-align:center'>"
         .Write "      <span id='text' name='text'></span>"
         .Write "    </div>"
         .Write "   </body>"
         .Write "</html>"
         ' Temporary Title
         .Title = "Progress Bar"
        End With
    End Function
 
    Public Function Close()
        m_ProgressBar.quit
'        m_ProgressBar = Nothing
    End Function
 
    Private Function UpdateProgressBar()
        If m_PercentComplete = 0 Then
            m_StatusBarText = ""
        End If
        For n = m_CurrentStep to m_PercentComplete - 1
            m_StatusBarText = m_StatusBarText & "|"
            m_ProgressBar.Document.GetElementById("statusbar").InnerHtml = m_StatusBarText
            m_ProgressBar.Document.title = n & "% Complete : " & m_Title
            m_ProgressBar.Document.GetElementById("pc").InnerHtml = n & "% Complete : " & m_Title
            wscript.sleep 10
        Next
        m_ProgressBar.Document.GetElementById("statusbar").InnerHtml = m_StatusBarText
        m_ProgressBar.Document.title = m_PercentComplete & "% Complete : " & m_Title
        m_ProgressBar.Document.GetElementById("pc").InnerHtml = m_PercentComplete & "% Complete : " & m_Title
        m_ProgressBar.Document.GetElementById("text").InnerHtml = m_Text
        m_CurrentStep = m_PercentComplete
    End Function
 
 End Class
 
  'Declare progressbar and percentage complete
 Dim pb
 Dim percentComplete
 'Setup the initial progress bar
 Set pb = New ProgressBar
 percentComplete = 0
 pb.SetTitle("Step 1 of 5")
 pb.SetText("Copying bin/Debug Folder")
 pb.Show()
 
 'Loop to update the percent complete of the progress bar
 'Just add the pb.Update in your code to update the bar
 'Text can be updated as well by pb.SetText
 Do While percentComplete <= 100
    wscript.sleep 500
    pb.Update(percentComplete)
    percentComplete = percentComplete + 10
 Loop
 wscript.sleep 3000
 
 'This shows how you can use the code for multiple steps
 'In a future iteration I will add a second bar to measure overall progress
 percentComplete = 0
 pb.SetTitle("Step 2 of 5")
 pb.SetText("Copying bin/Release Folder")
 pb.Update(percentComplete)
 Do While percentComplete <= 100
    wscript.sleep 500
    pb.Update(percentComplete)
    percentComplete = percentComplete + 10
 Loop
 pb.Close()
 wscript.quit
Comments