VB Petition

Source Code

    The following code snippets are presented as-is. They are not complete components, but are designed for copy-and-paste into your code.

rule1.gif (1558 bytes)

Get Process CPU Percentage

   This is a specialization of the "Use PDH Interface to capture NT Performance data" code (below). The code with automatically bring back all the processes running, and allow you to select one of those processes. If you then hit the <Start> button, you will see the percentage of CPU time in the listview control for that process.

Download: Pdh_Process_CPU

rule1.gif (1558 bytes)

Two Simple Add-In For VB 5.0/6.0

   These two simple add-ins for VB will allow you to add a comment block (in a modified "flower box") format) or add you initials to the end of a line of code.

    To install either of the add-ins, just run the compiled EXE and answer any questions it asks (like end column, or your initials).

    The comment block consists of the following:

       ' -----------------------------------
       ' -----------------------------------

    Note that as supplied, the comment will start on the nearest column to your cursor that is a multiple of three (i.e., you have the tabs set to 3 instead of the VB default of 4), and it will extend to column 48. You can change the "extend" column when you install the add-in, but to change the starting column you must change the code.

    The add-in to add your initials is based on code by Chris Barlow in Visual Basic Programmer's Journal (VBPJ), but adds your initials to the *end* of the line your cursor is on instead of adding your initials in a new line immediately above your current line (as in original article).

Download: InsertInitials

Download: InsertComments

rule1.gif (1558 bytes)

Register and Un-register TypeLibs: NT 3.50+, Win95

    Now you've created a really neat TypeLib to contain all your app's enums.  But there isn't a command-line utility to register or un-register that TypeLib.  This small applet will allow you to register and un-register that TypeLib from either the command line or from a GUI interface.

Download: RegTypeLib32

rule1.gif (1558 bytes)

Use TypeLib to encapsulate VB Enums: NT 3.50+, Win95

    Enums can be created in VB 4.0 or 5.0 classes.  But suppose you want to share those enums between multiple components.  Or if you want to actually document both the enum and the elements in the enum (so that the documentation is visible in the Object Browser)?  Well, this little text file will show you how.   Note that you will need MKTYPLIB.EXE (comes with C++) or equivalent to compile the ODL file into a TypeLib (TLB) file.  But after compiling, all you have to do is add a reference to the TypeLib in your program.

Download: TypeLib Text

rule1.gif (1558 bytes)

Use PDH Interface to capture NT performance data: NT 3.50+

    Performance data is crucial to monitoring an NT machine. In the September 1997 issue of VBPJ (Code for ToolHelp NT) I demonstrated how to use PSAPI.DLL to return a subset of the performance-data from NT and get the ToolHelp32 type of data programmatically. But to generically retrieve performance data, you need to use PDH.DLL.

     There are only 11 functions in the PDH.DLL specifically designed to be used by Visual Basic.  In the demo program below, I use 6 of those functions to produce a simple but functional demonstration of retrieving performance data.

Download: PDH Demo

rule1.gif (1558 bytes)

Clear Code Windows: VB 5.0

    Ever get tired of opening a group project and having 20 code windows pop up?  This little add-in automatically closes all code windows (but not forms) in the current project.

Download: Clear Code Windows

rule1.gif (1558 bytes)

Get Drive Type: VB 5.0

    Very simple demo of how to get the drive type of an attached drive.

Download: Get Drive Type

rule1.gif (1558 bytes)

Terminate Process: VB 5.0

    Sometimes programs, particularly 16-bit programs, mis-behave and must be terminated.  This is a very simple example on how to kill such a program.   There is no UI, and currently will only try to kill a program with a caption in the main window of "xxx-xxx", but it should give you enough to start on to create a more robust implementation.

Download: Terminate Process

rule1.gif (1558 bytes)


Last modified on: Tuesday March 08, 2005 07:08:40 PM