This handy VBScript class comes from Michael Balloni, who has authored a number of other articles on 4Guys (view Michael's 4Guys articles). This tip contains a VBScript class Michael sent in that creates a horizontal percentage bar gauge. (For information on what, exactly, classes are and how to use/create them in VBScript, be sure to read: Using Classes within VBScript!) For example, if you ran a testing site that quizzed users on some topic, you may wish to show the user their test scores graphically, like so:
You score an 87% on the test. Congratulations!
0 |
|
100% |
Michael uses this class on the site he works on, Streamload.com, to display various percentage information to his users.
With this class, creating such horizontal percentage gauges is a breeze - just instantiate the class, set a few properties, and call a method to generate the gauge. In fact, the above example uses the following simple, straightforward code (for brevity the actual class is not included in this sample code):
|
That's it! Note that to use this you will have to have a small (43 bytes), transparent GIF
file on your Web server that is used to help properly space out the HTML table that is used
to display the gauge. This image, 1_pix_trans.gif
, can be downloaded
here (right click on the link and choose save-as; since
the GIF is transparent, if you click on the link you will be shown the GIF, but you will not
see it (due to its transparency)).
Below you will find the complete source code to the class. Feel free to cut and paste the code into your application (or you can download the code in text format). There is also a live demo to try out.
Happy Programming!
Return to user tips... |
|
Return to user tips... |