All Forums >> [Scripting] >> Post a VBScript >> Progress / Activity Bar as a Class Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
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:
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.
This really should be in the other thread, but I guess it deosn't matter.
To answer your questions, :
quote:
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.
quote:
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.
quote:
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
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
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?
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
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.