mbt masai
 
Welcome !
         

                                
After experiencing a lot of down time, We decided to move this site to CrystalTech.com. CrystalTech.com is powered by only the finest Windows servers providing the best performance, reliability, and value anywhere.

 Progress / Activity Bar as a Class

Author Message
DiGiTAL.SkReAM

  • Total Posts : 1259
  • Scores: 7
  • Reward points : 0
  • Joined: 9/7/2005
  • Location: Clearwater, FL, USA
  • Status: offline
Progress / Activity Bar as a Class Tuesday, February 28, 2006 6:02 AM (permalink)
0
I have posted two progress bars. 

The HTA-based bar - cleaner, looks better, more stable during long executions - can be found here: http://www.visualbasicscript.com/m_32390/tm.htm


And the one posted below is the IE-based one.  I don't like this one as much as it is kinda limited as to what it looks like, and you can't get rid of the title bar. 
I am also no longer supporting it with additional code-updates so any errors are kinda stuck there. heh heh
But some folks like it so I'll leave it around.
=============


Here is a small class that I put together to have a progress or "wait-till-I'm-finished!" bar that pops up while the script goes on with other tasks.
It doesn't really show percent complete or anything, just a series of colored squares that move back and forth while it is showing.  This goes on until
the window is closed.
The text it displays can also be changed on the fly, to reflect changes in status, etc.
This is a pretty heavily modified version of an actual progress indicator from the web, made into a class for ease of use.
Attached is a screenshot of what it looks like when running:


 Class ProgressBar
 ' This class allows the creation of an object for use in displaying a
 ' "progress bar" type of display to the user while the script performs
 ' other tasks int he background.  Very usefull to show that the script
 ' is still working or has finished.
 ' Usage: First, create a new instance of the object with a unique name.
 '    set oMyNewProgressBar = New ProgressBar
 ' Then, call the object's .StartBar function with an argument of the 
 ' initial message that you wish to display.
 '  oMyNewProgressBar.StartBar "This is my message.  Please wait."
 ' Then, if you want to change the displayed message, call the object's
 ' .SetLine function with an argument of what you want to change the
 ' message to.
 '  oMyNewProgressBar.SetLine "This is my new message.  Wait longer."
 ' To close the object, call it's .CloseBar function.
 '  oMyNewProgressBar.CloseBar
 Dim oWaitBarIE, oTextLine, oProgressBar, oQuitFlag
 Public Function StartBar(sMessageToDisplay)
   Set oWaitbarIE = CreateObject("InternetExplorer.Application")
    With oWaitbarIE
     .height = 230
     .width = 400
     .menubar = False
     .toolbar = false
     .statusbar = false
     .addressbar = False
  .Navigate("about:blank")
 End With 
 fWriteHtmlToDialog oWaitbarIE.Document
   set oTextLine = oWaitbarIE.Document.All("txtMilestone")
   Set oProgressBar = oWaitbarIE.Document.All("pbText")
   set oQuitFlag = oWaitbarIE.Document.Secret.pubFlag
   oTextLine.innerTEXT = sMessageToDisplay
   oWaitbarIE.visible = True
   oShell.AppActivate("PLEASE WAIT - Microsoft Internet Explorer")
 End Function
 Public Function CloseBar()
 On Error Resume Next
 oWaitbarIE.quit
 End Function 
 Public Function SetLine(sNewText)
 'On Error Resume Next
 oTextLine.innerTEXT = sNewText
 End Function 
 Private Function fWriteHtmlToDialog(oDocument)
 Const conBarSpeed = 80
 With oWaitbarIE.Document
  .Open
  .Writeln "<html>"
  .Writeln "<title>PLEASE WAIT</title> "
  .Writeln "<style>"
  .Writeln " BODY {background: Silver} BODY { overflow:hidden }"
  .Writeln " P.txtStyle {color: Navy; font-family: Verdana; font-size: 10pt; font-weight: bold; margin-left: 10px } "
  .Writeln " input.pbStyle {color: navy; font-family: Wingdings; font-size: 10pt; background: Silver; height: 20px; width: 340px } " 
  .Writeln "</style>"
  .Writeln "<div id=""objProgress"" class=""Outer""></div>"
  .Writeln "<CENTER>"
  .Writeln "<P id=txtMilestone class='txtStyle' style='margin-left: 10px'> </P>"
  .Writeln "<input type='text' id='pbText' class='pbStyle' value='' >" 
  .Writeln "<br><br>"
  .Writeln "</CENTER>" 
  .Writeln "<form name='secret' ><input type='hidden' name='pubFlag' value='run' ></form>" 
  .Writeln "<SCRIPT LANGUAGE='VBScript' >" 
  .Writeln "Function PctComplete(nPct)"
  .Writeln "pbText.Value = String(nPct,"" "") & String(4,""n"")"
  .Writeln "End Function"
  .Writeln "Sub UpdateProgress()"
  .Writeln "Dim intStep"
  .Writeln "Dim intDirection"
  .Writeln "If (IsNull(objProgress.getAttribute(""Step"")) = True) Then"
  .Writeln "intStep = 0"
  .Writeln "Else"
  .Writeln "intStep = objProgress.Step"
  .Writeln "End If"
  .Writeln "if (IsNull(objProgress.GetAttribute(""Direction""))=True) Then"
  .Writeln "intDirection = 0"
  .Writeln "Else"
  .Writeln "intDirection = objProgress.Direction"
  .Writeln "End If"
  .Writeln "if intDirection=0 then"
  .Writeln "intStep = intStep + 1"
  .Writeln "else"
  .Writeln "intStep = intStep - 1"
  .Writeln "end if"
  .Writeln "Call PctComplete(intStep)"
  .Writeln "if intStep>=23 then"
  .Writeln "intDirection=1"
  .Writeln "end if"
  .Writeln "if intStep<=0 then"
  .Writeln "intDirection=0"
  .Writeln "end if"
  .Writeln "objProgress.SetAttribute ""Step"", intStep"
  .Writeln "objProgress.SetAttribute ""Direction"", intDirection"
  .Writeln "Window.setTimeout GetRef(""UpdateProgress""), " & conBarSpeed
  .Writeln "End Sub"
  .Writeln "Sub Window_OnLoad()"
  .Writeln "theleft = (screen.availWidth - document.body.clientWidth) / 2"
  .Writeln "thetop = (screen.availHeight - document.body.clientHeight) / 2"
  .Writeln "window.moveTo theleft,thetop"
  .Writeln "window.opener = ""x"""
  .Writeln "Window.setTimeout GetRef(""UpdateProgress""), " & conBarSpeed
  .Writeln "End Sub"
  .Writeln "</SCRIPT>"
  .Writeln "</html>"
  .Close 
 End With 
 End Function
 End Class
 



[image]local://8013/C53295005FC44ABC81A7D117E7A8B5C1.JPG[/image]
<message edited by DiGiTAL.SkReAM on Tuesday, July 04, 2006 12:09 PM>
Attachment(s)Attachments are not available: Download requirements not met
"Would you like to touch my monkey?" - Dieter (Mike Meyers)

"It is better to die like a tiger, than to live like a pussy."
-Master Wong, from Balls of Fury
#1
    ebgreen

    • Total Posts : 8081
    • Scores: 94
    • Reward points : 0
    • Joined: 7/12/2005
    • Status: offline
    RE: Progress / Activity Bar as a Class Wednesday, March 01, 2006 3:34 AM (permalink)
    0
    Very nice. I plan to shanelessly steal this code promptly. 
    "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
    Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
    http://www.visualbasicscript.com/m_47117/tm.htm
    #2
      Jack in the Box

      • Total Posts : 6
      • Scores: 0
      • Reward points : 0
      • Joined: 4/1/2006
      • Status: offline
      RE: Progress / Activity Bar as a Class Tuesday, July 04, 2006 4:03 AM (permalink)
      0
      Thanks for the updated code.  I've been using your HTA-based progress bar since I first found it and I just happened to come back and see you updated your original post with an IE based progress bar.  I like the changes.

      There is one minor error, you're missing the the following line somewhere before Line 41:

      Set oShell = CreateObject("Wscript.Shell")

      Other then that this piece of code works brilliantly.  Thanks again.
      #3
        Fredledingue

        • Total Posts : 572
        • Scores: 0
        • Reward points : 0
        • Joined: 5/9/2005
        • Location: Europe
        • Status: offline
        RE: Progress / Activity Bar as a Class Monday, July 10, 2006 10:23 AM (permalink)
        0
        Very nice little progressbar.
         
        But why so complicated?
         
        20 lines to erase a registry key, 25 lines to delete a file... are you working for M$ or what?
         
        The most incredible is maybe using the dictionary to form the hta code in a text string.
        Why not using...:
         
        HTAcode  =   "some line of code" _
        & VbCrlf & "some more line of code" _
        & VbCrlf & "some more line of code" _
        & VbCrlf & "some more line of code"
         

         
         
        Fred
        #4
          DiGiTAL.SkReAM

          • Total Posts : 1259
          • Scores: 7
          • Reward points : 0
          • Joined: 9/7/2005
          • Location: Clearwater, FL, USA
          • Status: offline
          RE: Progress / Activity Bar as a Class Tuesday, July 11, 2006 6:12 AM (permalink)
          0
          This really should be in the other thread, but I guess it deosn't matter.
           
          To answer your questions, :
           


          20 lines to erase a registry key

           
          The 20 lines you mention are part of the subKillRegistrykey subroutine.  That routine is taken almost verbatim from the includes file that I use in all of my scripts.  Since it is in the includes file, it needs to be as generic as possible so that it can be used in many different scripts.  And since I am lazy by nature, i figured I would just paste it in with a minimum of trimming... it doesn't hurt anything, and heck, someone else might want to pilfer the code for use in their own scripts in a different way. 
           
          Also, you will notice that it will delete a key, even if there are values, or subkeys under it.
           


          25 lines to delete a file

           
          By this, I assume that you are referring to the fKillFile function.  That routine is taken almost verbatim from the includes file that I use in all of my scripts.  Since it is in the includes file, it needs to be as generic as possible so that it can be used in many different scripts.  And since I am lazy by nature, i figured I would just paste it in with a minimum of trimming... it doesn't hurt anything, and heck, someone else might want to pilfer the code for use in their own scripts in a different way.
           


          The most incredible is maybe using the dictionary to form the hta code in a text string.
          Why not using...:

          HTAcode  =   "some line of code" _
          & VbCrlf & "some more line of code" _
          & VbCrlf & "some more line of code" _
          & VbCrlf & "some more line of code"

           
          I use a dictionary object because that is how I do my string concatenation.  It is about 250 times faster - on average - than doing string = string & newstring.
          Of course, if you were just going to be catting a small string
           sMyString = "Fred" & "ledingue"
           

           
          then yes, it would be faster to use strings.  BUT, if you are doing a large amount of catting, then it is undeniably faster to use arrays or dictionaries for that than to use strings.  We've done studies on this previously here in the forums, and it has been confirmed.  Because of this speed benefit, I use dictionaries almost exclusively for my string concatenation through the use of a class to handle them that, once again, is in my includes file.
           
          Now, the reason that I included all of these "bloated" functions and subroutines in my ProgressBar class is because they
          1.) Work with no difficulty
          2.) Provide others with ready-made functions and subs that they can use int heir scripts, almost verbatim from what I have posted here
          3.) Are easily pasted in to make my job easier

           
          "Would you like to touch my monkey?" - Dieter (Mike Meyers)

          "It is better to die like a tiger, than to live like a pussy."
          -Master Wong, from Balls of Fury
          #5
            ebgreen

            • Total Posts : 8081
            • Scores: 94
            • Reward points : 0
            • Joined: 7/12/2005
            • Status: offline
            RE: Progress / Activity Bar as a Class Tuesday, July 11, 2006 7:26 AM (permalink)
            0
            If it makes you feel any better it takes me just shy of 900 lines to write a line to a text file using my Logger class. 
            "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
            Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
            http://www.visualbasicscript.com/m_47117/tm.htm
            #6
              Fredledingue

              • Total Posts : 572
              • Scores: 0
              • Reward points : 0
              • Joined: 5/9/2005
              • Location: Europe
              • Status: offline
              RE: Progress / Activity Bar as a Class Tuesday, July 11, 2006 12:11 PM (permalink)
              0
              No problem, Digital Skream!
               
              I was just curious. And I agree: [sarcasm] the most important goal of these routines is that others can use them too in other script. If a beginner reads one of your script, he will learn about almost all the possibilities of VBS. [/sarcasm]
               
              I will analys this interrresting script again in the future. I will find many things that I don't know. Thanks.

               
              About the concatenation of the string... I agree that using arrays and dictionary is much faster than "var = var & text". I myself made some experiments and attended the conversation.
              What I don't undertsand is why you need to "concatenate" this string, (except for the fun of it).... because it's a static string!
              Look:
              in
               
              HTAcode  =   "some line of code" _
              & VbCrlf & "some more line of code" _
              & VbCrlf & "some more line of code" _
              & VbCrlf & "some more line of code"
               
              There is no event, just a value given to a variable.
              You could write it like that as well:
               
              HTAcode  =   "some line of code" & VbCrlf & "some more line of code" & VbCrlf & "some more line of code" & VbCrlf & "some more line of code"
               
              ...but that's not easy to read in the editor.

              In the case of creating an HTA the VbCrlf's are superflous. They are useful only if you want to read the HTA source later for checking.
              So it can be like this:
               
              HTAcode  =   "some line of code" _ 
              & "some more line of code" _ 
              & "some more line of code" _ 
              & "some more line of code"
               
              Or does it still takes more time than dashing them in a dictionary?
              What does take time is this:
               
              HTAcode  = HTAcode & VbCrlf &  "some line of code"
              HTAcode  = HTAcode & VbCrlf & "some more line of code"
              HTAcode  = HTAcode & VbCrlf & "some more line of code"
              HTAcode  = HTAcode & VbCrlf & "some more line of code"
               
              ...because the variable is everytime rewritten in the memory (as I understand). Not when you set it once.
              Am I wrong?

              Fred
              #7
                DiGiTAL.SkReAM

                • Total Posts : 1259
                • Scores: 7
                • Reward points : 0
                • Joined: 9/7/2005
                • Location: Clearwater, FL, USA
                • Status: offline
                RE: Progress / Activity Bar as a Class Tuesday, July 11, 2006 10:57 PM (permalink)
                0

                ORIGINAL: Fredledingue

                No problem, Digital Skream!

                I was just curious. And I agree: [sarcasm] the most important goal of these routines is that others can use them too in other script. If a beginner reads one of your script, he will learn about almost all the possibilities of VBS. [/sarcasm]

                I will analys this interrresting script again in the future. I will find many things that I don't know. Thanks.


                 
                Why are you so mad?  I've not been insulting at all, nor have I been a jerk about any of this.  I've just explained why I posted the non-optimized (read: contains more code than is strictly needed to do the job) code that I did, since you questioned me about it.  What's the big deal?  At no point have I ever said that "if a beginner reads one of my scripts he will learn almost all the possibilities of VBS". 
                 
                I freely admit that i have only been writing vbscript for about a year now.  Before that, I was limited to quickbasic 4.5 and batch.  So what I don't understand is the sarcasm and general anger that the above snippet of yours seems to be portraying towards me. 
                I was under the impression that the purpose of posting code in the Post a VBScript forum was to share snippets of code that we find interesting or usefull and want to share with the community.  If I was mistaken, i sincerely apologize and won't do it again.  I did not mean to step on anyone's toes by posting code or trying to help others with their questions.
                 
                I will leave the posting to those of you with far more experience.
                 
                "Would you like to touch my monkey?" - Dieter (Mike Meyers)

                "It is better to die like a tiger, than to live like a pussy."
                -Master Wong, from Balls of Fury
                #8
                  ehvbs

                  • Total Posts : 3310
                  • Scores: 110
                  • Reward points : 0
                  • Joined: 6/22/2005
                  • Location: Germany
                  • Status: offline
                  RE: Progress / Activity Bar as a Class Wednesday, July 12, 2006 12:23 AM (permalink)
                  0
                  Hi DiGiTAL.SkReAM,

                  Quote:

                     I will leave the posting to those of you with far more experience.

                  Please don't! I would miss your contributions.

                  ehvbs

                  #9
                    Fredledingue

                    • Total Posts : 572
                    • Scores: 0
                    • Reward points : 0
                    • Joined: 5/9/2005
                    • Location: Europe
                    • Status: offline
                    RE: Progress / Activity Bar as a Class Wednesday, July 12, 2006 1:40 AM (permalink)
                    0
                    DigitalSKREAM,
                     
                    I'm not mad at all and I sincerly do appreciate your input on this forum and your progressbar script in particular.
                    What I meant above is that, indeed, we can learn a lot of things by reading your code.
                    I apologize if my reply sounded offensive. It was not intended to be so.
                     
                     
                     
                     
                     
                     
                    Fred
                    #10
                      Fredledingue

                      • Total Posts : 572
                      • Scores: 0
                      • Reward points : 0
                      • Joined: 5/9/2005
                      • Location: Europe
                      • Status: offline
                      RE: Progress / Activity Bar as a Class Wednesday, July 12, 2006 12:51 PM (permalink)
                      0
                      DiGiTAL.SkReAM
                       
                      Here is a link for you
                       
                      http://www.gnu.org/fun/jokes/helloworld.html
                       
                      Seasoned professional! LOL!
                      Fred
                      #11
                        NssB

                        • Total Posts : 31
                        • Scores: 0
                        • Reward points : 0
                        • Joined: 6/26/2006
                        • Status: offline
                        RE: Progress / Activity Bar as a Class Thursday, July 13, 2006 4:51 AM (permalink)
                        0

                        Seasoned professional! LOL!


                         #include <iostream.h>
                          #include <string.h>
                          class string
                          {
                           private:
                            int size;
                            char *ptr;
                           public:
                            string() : size(0), ptr(new char('\0')) {}
                            string(const string &s) : size(s.size)
                            {
                              ptr = new char[size + 1];
                              strcpy(ptr, s.ptr);
                            }
                            ~string()
                            {
                              delete [] ptr;
                            }
                            friend ostream &operator <<(ostream &, const string &);
                            string &operator=(const char *);
                          };
                         								     
                          ostream &operator<<(ostream &stream, const string &s)
                          {
                            return(stream << s.ptr);
                          }
                          string &string::operator=(const char *chrs)
                          {
                            if (this != &chrs)
                            {
                              delete [] ptr;
                              size = strlen(chrs);
                              ptr = new char[size + 1];
                              strcpy(ptr, chrs);
                            }
                            return(*this);
                          }
                          int main()
                          {
                            string str;
                            str = "Hello World";
                            cout << str << endl;
                            return(0);
                          }



                        Seasoned what??

                        Clearly does not get out much and has too much time on one's hands!
                        Its all about the code!
                        #12

                          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.8
                          mbt shoes www.wileywilson.com