Simple VBScript Progress Bar Class

Author Message
WolfZombie

  • Total Posts : 3
  • Scores: 0
  • Reward points : 0
  • Joined: 7/16/2009
  • Status: offline
Simple VBScript Progress Bar Class Thursday, July 16, 2009 7:31 AM (permalink)
0
This is for a simple progress bar using InternetExplorer within VBScript.  It doesn't write to any files and is contained in a class to be easily reused.  It is modified from code that I originally found here. Anyone know a good way to get rid of the "http:///" in the title bar?
Enjoy!



Class:
 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()
        Set m_ProgressBar = CreateObject("InternetExplorer.Application")
        'in code, the colon acts as a line feed
        m_ProgressBar.navigate2 "about:blank" : 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.document.write "<body Scroll=no style='margin:0px;padding:0px;'><div style='text-align:center;'><span name='pc' id='pc'>0</span></div>"
        m_ProgressBar.document.write "<div id='statusbar' name='statusbar' style='border:1px solid blue;line-height:10px;height:10px;color:blue;'></div>"
        m_ProgressBar.document.write "<div style='text-align:center'><span id='text' name='text'></span></div>"
    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
 


Usage:
 '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
 
Coding Examples, Samples, and Tutorials - www.NorthAtlantaWebDesign.com
 
#1
    Fredledingue

    • Total Posts : 572
    • Scores: 2
    • Reward points : 0
    • Joined: 5/9/2005
    • Location: Europe
    • Status: offline
    RE: Simple VBScript Progress Bar Class Thursday, July 16, 2009 9:39 AM (permalink)
    0
    It's more efficient to have the html code in an hta file rather than launching an IE instance.
    Mshta loads much faster than IE and is more flexible.
    You can  embed your vbscript to the progressbar hta instead of using the navigate method.
    It will look exactely the same but it could also solve the title issue.
    Fred
     
    #2
      WolfZombie

      • Total Posts : 3
      • Scores: 0
      • Reward points : 0
      • Joined: 7/16/2009
      • Status: offline
      RE: Simple VBScript Progress Bar Class Friday, July 17, 2009 2:41 AM (permalink)
      0
      Is there a way to run and interact with the HTA file through the vbscript file?
      Coding Examples, Samples, and Tutorials - www.NorthAtlantaWebDesign.com
       
      #3
        VBScab

        • Total Posts : 1
        • Scores: 0
        • Reward points : 0
        • Joined: 12/8/2005
        • Status: offline
        RE: Simple VBScript Progress Bar Class Wednesday, August 05, 2009 6:14 AM (permalink)
        0
        > Anyone know a good way to get rid of the "http:///" in the title bar?

        Yes. In your HEAD section, use the TITLE tag, the same as you would for an HTML page.
        <TITLE>Progress Bar Demo</TITLE>
         
         
        #4

          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