Category Archives: VB 6.0 and .NET Compatible

The contents under this category may be related to both VB 6.0 and Visual Basic.NET and newer versions.

How to Play Two Audio Files at the Same Time in VB 6.0 and VB.NET

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)

How you can easily Play 2 or more Audio files Simultaneously using Visual Basic 6.0 and Visual Basic.NET

This article will be using the MCISendString function via the ‘winmm.dll’ library to control the playback and properties of multiple audio files independently from one another. You can mix and match file types like .mp3, .wav, .wma, and .midi files or clips as well.

If you’ve never worked with the Windows Multimedia Command Interface before I suggest you check out my beginner tutorial at this link for an easy step by step guide. It should get you started with a good understanding of the basics on sending Command Strings with the MCISendString function.

Note: The .NET code in this article is compatible with the original versions as well as the 2005, 2008, VB 2010, and newer versions.

Continue reading

Visual Studio Community 2013 and Visual Studio 2015 Preview

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)

Update Edit: Dec 12th 2014: Just wanted to mention that Microsoft has recently released a video about the Community Edition of Visual Studio 2013. You can watch the video by clicking here.

Microsoft has announced two new releases or additions to their Visual Studio.NET platform. A preview version of Visual Studio 2015, and a new ‘Community Edition’ of VS 2013 ready for downloading. I am personally interested in the 2013 Community version of VB. I usually use the Express Edition of Visual Basic 2010 for most things and would like a couple features not available with VB 2010 Express.

So, is Visual Studio Community 2013 just mildly enhanced Express Editions? Nope, not at all. In fact, you can think of it as Visual Studio 2013 Professional Edition according to Microsoft. A huge part of Pro over Express that I desired was the support for Add-ins/Extensions. There are literally thousands of extensions available including many being completely Free. You can check out the extensions by clicking here

Continue reading

Free Visual Basic Icons and Image Resources! | Updated

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (39 votes, average: 4.15 out of 5)

Free VB and Visual Basic.NET icons for your programs and applications!

Icons or Images can really enhance your Visual Basic 6.0 and Visual Basic.NET applications. Unfortunately a lot of the Icons you find either cost money and/or will not allow you to use them in a commercial application. So that is where this little post comes in. I have sources below that’s either free for all uses or free for non-commercial.  I will continue to add sources as they are found. Leave a comment if you have another good source to add here.

Note: While VB 6.0 and VB.NET may come with icons, you may want something a little newer or more unique. That’s why I made this post.

Starting below are sources for free VB 6.0 Icons and Visual Basic .NET icons

Continue reading

Advanced Textbox Manipulation in Visual Basic and VB.NET | Part 2

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (3 votes, average: 4.33 out of 5)

This is Part Two of the Advanced Textbox Control Manipulation series. If you haven’t already you should check out Part 1 of this series. That article showed how to use the SendMessage API call to make a Textbox control Page Left, Page Right, Line Left, Line Right, Left Edge, and go to the Right Edge of the contents. This Part 2 post will show how to add the functionality that is outlined below…

Page UP

Page Down

Line UP

Line Down

Top Edge

Bottom Edge

Note: These codes are basically taken from an example I for VB.NET that shows lots and lots of various textbox based manipulating and functionality. Just go to under the Visual Basic.NET – Examples page.

Continue reading

Getting the Computers Windows Directory using VB and Visual Basic.NET

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (3 votes, average: 3.67 out of 5)

This little article will show you how to get the Windows directory/folder using both classic vb and For some reason Microsoft didn’t add built-in support for getting the path of the users windows directory until .NET 4.0. It is located under the: Environment.SpecialFolders feature. Otherwise I will show a way to get the windows path in the earlier versions of VB.NET and a way to get the directory path using VB 6.0 and Visual Basic.NET.

Both VB6.0 and Visual Basic NET

This is a simple API call that will give you the windows installed directory for the computer. You just need to create a string buffer and the api function will set the information you want in that buffer.

'Visual Basic 6.0 Declare

  Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
'Visual Basic.NET Declare

 Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Int32) As Int32

Remaining code for API Method for All VB’s below…

'For both VB and VB.NET. This variable is for receiving the path from the API call.

    Dim winDir As String

 'Create a simple string buffer that will be passed to the api call to receive the directory for windows.

     winDir = Space$(255)

  'The winDir variable will get the value from the api call.

      GetWindowsDirectory winDir, Len(winDir)

'Trim the end of the value to remove the unused whitespaces from the string buffer.

      winDir = RTrim(winDir)

'This should throw a message box displaying the windows directory for the target computer.


When executing the code above, you should get a messagebox with the target computers Windows directory. It could be something similar to: “C:\Windows”

.NET based only using MY. below

Like I mentioned earlier Microsoft failed to include the Windows Directory as a Special Folder until .NET 4.0. But there is a another easy way to do it if you don’t want to use the API method.

This first way will actually use the Special Folder feature in .NET but will target the Environment.SystemDirectory. Since the System32 directory is always located under the base windows folder all you have to do is get the parent path of the SystemDirectory.


The code above will throw a message with the parent path for the System32 directory. In my case is returned ‘c:\Windows’ just like the API version did.

There are other ways to get the windows direcory like checking a environment variable that I might add later on. The API version works great for both VB 6.0 and VB.NET, and the System32 method works just fine for .NET.  Remember Microsoft included the WindowsDirectory as a SpecialFolder in Visual Basic 2010 so you should use that method if possible. Anyways, thats all!


Revised: 2015

Hide/Show the Cursor’s Caret using VB and VB.NET

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (5 votes, average: 5.00 out of 5)

There may be times when you don’t want your textbox or combobox to show the cursor’s caret position (blinking cursor). Thanks to a couple API calls, its easy to both hide and show the caret from the user. Microsoft made available the HideCaret and ShowCaret api functions.

I want to explain alittle more how the functions operate. Whenever you want to hide the caret using the HideCaret api call, say on one of your textbox controls, the target textbox needs to have ownership of the caret at the time the Hide Caret function is executed. Whenever the textbox loses ownership of the caret it will be reset back to the default setting. For example you call the HideCaret function which successfully hides the blinking cursor in the target textbox control. You then click on a button or another control that gets focus/ownership of the caret, then the caret/blinking cursor will be shown again in the target textbox when the user clicks or gives focus to the target textbox again. In other words, whenever ownership of the caret changes from one control to another then the Caret will reset back to its default setting. So, if you want the caret to always remain hidden from the user in your textbox, then you can do a simple trick to keep the blinking cursor from being shown even when it changes ownership.

First of all, you need to get the code for the two API calls…


Private Declare Function HideCaret Lib “user32? (ByVal wHandle As Int32) As Int32

Private Declare Function ShowCaret Lib “user32? (ByVal wHandle As Int32) As Int32

VB 6.0

Private Declare Function HideCaret Lib “user32? (ByVal wHandle As Long) As Long

Private Declare Function ShowCaret Lib “user32? (ByVal wHandle As Long) As Long

The functions are easy to use. All you have to do is call the two functions with the handle of the control whose caret you want to hide or show in the wHandle parameter like below…




VB 6.0

    HideCaret Text1.hWnd

    ShowCaret Text1.hWnd

The codes above set to Hide/Show the caret in a textbox control.

If you want the cursor to never be shown in a textbox control, then simply put the HideCaret code in the Textbox_GotFocus() event. Like below…


Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.GotFocus


End Sub

VB 6.0

Private Sub Text1_GotFocus()


End Sub

With the code above, now each time the textbox control gets focus and ownership of the caret it will automatically call the HideCaret function. Thus the user should never see the blinking cursor at all.

That’s all for this tip I guess. 🙂


Minor Revision: 2015

Open a Folder/Directory and Select/Highlight a Specific File

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)

Have you ever seen a program that can open a files destination/containing folder and also highlight/select the filename as well in the opened folder window? This will show you a simple way to do the same thing. Basically your using shell to access explorer.exe while passing certain command line arguments. All versions of Visual Basic and Visual Basic.NET can easily interface with with the explorer.exe process. VB.NET, VB 2008, Visual Basic 2010, and higher will use the same code. VB 6.0 will need an additional piece of code to open the process. The target .exe and argument text passed on are used for all VB’s however.

VB 6.0 will need to add the API shell code below to the Declarations section…

Private Declare Function ShellExecute Lib “shell32.dll” Alias “ShellExecuteA” ( ByVal hwnd As Long , ByVal lpOperation As String , ByVal lpFile As String , ByVal lpParameters As String , ByVal lpDirectory As String , ByVal nShowCmd As Long ) As Long


Then call the ShellExecute function and pass the proper parameter arguments.  Here is the code to open the folder and select a filename using VB 6.0…

ShellExecute  Me.hwnd, vbNullString, “explorer” , “/select,” & “c:\” , vbNullString, 1


Visual Basic .NET has built-in support for running shell based code by using the Process class. Using this class is very simple. Just add the proper arguments and parameters like below…

Process.Start( “explorer” , “/select,” & “c:\myFileToOpen.txt”)

Thats all there is to it! As you can see its a very simple code to perform this functionality. Hope this little snippet and article proves helpful to you!


Revised: 2014

Updated: USB using Visual Basic.NET and VB 6.0

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (10 votes, average: 3.20 out of 5)

The purpose of this post is simply to give some info to help with usb programming like detecting when a usb device has been added/removed, which the .NET based class helps with, ect…

Visual Basic 6.0

The first library is for Visual Basic 6.0 and is provided by Intel (Intel is the main inventer of USB as well) and includes various bas/modules for use in your applications. BTW, these  VB 6.0 USB modules do more than the below .NET library.

Click here for the Main Intel page with the downloads and tutorial…

Edit: The Intel link above is no longer valid. I have not been able to find where it was moved to or if its completely taken away. I still have the VB Bas files that are needed to do the USB programming.

Click here to download the modules.

Visual Basic.NET Compatible Class Library

Strolling through some of the latest updates at I noticed someone made a USB library using C# for detecing the attachment and detachment events of usb devices. He provides the source code, compiled class, and a demo app with the usb library in action. If you simply want to reference the class download the source code version. Then under the Bin/Release directory you will see the ‘USBClassLibrary.Dll’ which is what you want to reference.

Click here for the main USB Library page…

Hopefully this post was of some help. Have Fun!


Small Basic – Beginner Programming Language

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (11 votes, average: 4.09 out of 5)

Small Basic – New Beginner Programing Language

Microsoft appears to be supporting a somewhat newer programming language called SmallBasic. As the name implies it is not a full-featured language like VB.NET or C++/C#. In fact, it appears to only support 15 or so Keywords. But it does get access to version 3.5 of the Dot .NET Framework from what I have gathered. And looks like it uses alot of the VB based syntax, although C# syntax might be used but I am not sure. There are some game source codes like Tetris and Snake that uses the Small-Basic language. Below are some resources you can check out if your interested. I will also place the main Small Basic link on the Free IDE/Compiler Downloads page when I get time.

MSDN Microsoft Forward Explanation

Small Basic is a project that’s aimed at bringing “fun” back to programming. By providing a small and easy to learn programming language in a friendly and inviting development environment, Small Basic makes programming a breeze. Ideal for kids and adults alike, Small Basic helps beginners take the first step into the wonderful world of programming.

  • Small Basic derives its inspiration from the original BASIC programming language, and is based on the Microsoft .Net platform. It is really small with just 15 keywords and uses minimal concepts to keep the barrier to entry as low as possible.
  • The Small Basic development environment is simple, yet provides powerful modern environment features like Intellisense™ and instant context sensitive help.
  • Small Basic allows third-party libraries to be plugged in with ease, making it possible for the community to extend the experience in fun and interesting ways.

Main Resources Links


Main Small basic DevLabs Page – Click Here


Main Small-Basic MSDN/Microsoft Page – Click Here


Small Basic Program IDE Setup – Click Here


API Reference for Small Basic – Click Here


Small Basic MSDN Forums/Threads – Click Here


PDF for Getting Started – Click Here

Game Examples

Tetris Example: This game is based on Small Basic and uses about 530 lines of code. It looks like a well-done, completed game. Click Here

Snake Game Example: If you are interested in a Snake type game, there is a example that of course uses SmallBasic. Click Here

Thats all for now. If your interested then hopefully this page will help someone to get started in the Windows based programming world… Have Fun!


Advanced Textbox Manipulation in Visual Basic and VB.NET | Part 1 of 2

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (20 votes, average: 3.95 out of 5)

This is the first post in a two part series on how to do add some extra textbox features not exposed in your normal VB or VB.NET textbox. For instance, Page Left/Right and Line Up/Down.

Note: These codes are basically taken from an example I made at my site for VB.NET that shows how to do lots and lots of various textbox based manipulating. Just go to under the Visual Basic.NET – Examples page.

So in Part #1 I will provide code to add six new abilities to a Textbox control…

  • Page Left
  • Page Right
  • Line Left
  • Line Right
  • Left Edge
  • Right Edge

To accomplish these features I will use the tried and true Windows API. Specifically the SendMessage Function.

First is the API function

Visual Basic 6.0

    'Used to Send Messages to the control.
    Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal winHandle As Long, _
        ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Visual Basic.NET, VB 2008 and Visual Basic 2010

    'Used to Send Messages to the control.
    Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal winHandle As Int32, _
        ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As Int32) As Int32

Now for some Constants…

Visual Basic 6.0

    Private Const EM_SCROLL = &HB5

    Private Const SB_PAGEDOWN = 3

    Private Const SB_PAGEUP = 2

    Private Const SB_LINEUP = 0

    Private Const SB_LINEDOWN = 1

    Private Const SB_BOTTOM = 7

    Private Const SB_TOP = 6

Visual Basic.NET through VB 2008, VB 2010, and newer

    Private Const EM_SCROLL As Int32 = &HB5

    Private Const SB_PAGEDOWN As Int32 = 3

    Private Const SB_PAGEUP As Int32 = 2

    Private Const SB_LINEUP As Int32 = 0

    Private Const SB_LINEDOWN As Int32 = 1

    Private Const SB_BOTTOM As Int32 = 7

    Private Const SB_TOP As Int32 = 6

All that’s really needed is the Textbox you want to manipulate and call Sendmessage with the right combination of constants to perform the intended function.

NOTE: If your using VB 6.0 then change one thing in the rest of the code below…

  • Instead of txtControl.Handle.ToInt32, make it txtControl.hWnd

That’s basically the only change needed.

Page Left / Page Right

        'Move the position pageleft.
        SendMessage txtControl.Handle.ToInt32, WM_HSCROLL, SB_PAGELEFT, 0

        'Move the position pageright.
        SendMessage txtControl.Handle.ToInt32, WM_HSCROLL, SB_PAGERIGHT, 0

Line Left / Line Right

        'Move the position left.
        SendMessage txtControl.Handle.ToInt32, WM_HSCROLL, SB_LINELEFT, 0

        'Move the position right.
        SendMessage txtControl.Handle.ToInt32, WM_HSCROLL, SB_LINERIGHT, 0

Left Edge / Right Edge

        'Move the position to the left edge.
        SendMessage txtControl.Handle.ToInt32, WM_HSCROLL, SB_LEFT, 0

        'Move the position to the right edge.
        SendMessage txtControl.Handle.ToInt32, WM_HSCROLL, SB_RIGHT, 0

As you can see these non-native features were simple to add and configure.

Part #2 will go over:

  1. Page Up
  2. Page Down
  3. Line Up
  4. Line Down
  5. Top Edge
  6. Bottom Edge

Well that’s basically it for this article, Have fun!


Revised: 2014

How-to Playback Movies and Videos with VB and Visual Basic .NET

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (25 votes, average: 4.12 out of 5)

As you will see, playing videos is easy using the Windows MCI Command interface for the playback which is supported in Windows XP, Windows Vista, Windows 7, Windows 8, and Windows 10. Specifically the MCISendString function will be used in this tutorial.

MCI should by default already support the common formats like avi, mpg, mpeg, wmv, etc. with a basic Windows installation. But you can actually get MCI to playback nearly all formats if the correct Codec/Driver is installed. For Example, you can playback Apple QuickTime .Mov, MPEG 4 DivX, or H.264 .MP4 by simply installing the codec for each format. After that just program the device like you normally would.

This article is only to show how to do basic playback of videos and not features like duration/length, position, or resizing the video. You can check out my MCI MultiMedia Tutorial to learn how to program MCI and add your own features.

If your using VB 6.0 select the correct MCISendString declare below, change any IntPtr.Zero code to 0, and use ‘.hWnd’ instead of ‘.Handle’.

Edit: 2014, December 17th: I decided to make a download available that uses all of the codes in this article with a couple extras to help resizing and such. I also changed some of the code in the program for Option Explicit.

Download Example: Click Here

View Screenshot: Click Here

Visual Basic 6.0 and Older

    'The Main API call that will be used for the playback.
    Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal _
        lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As _
            Long, ByVal hwndCallback As Long) As Long


Visual Basic.NET and Newer

    'The Main API call that will be used for the playback.
    Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal _
        lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As _
            Integer, ByVal hwndCallback As IntPtr) As Integer


OR You Can Use…

    'The main API call.
    <DllImport("winmm.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
    Public Shared Function mciSendString(commandString As String, returnString As String, _
        returnStringLength As Integer, _mciCallback As IntPtr) As Int32
    End Function

Now make a couple variables.

    'Will hold the path to the movie file.
    Dim filename As String

    'Holds the return value of mciSendstring. Not used for anything in this article though.
    Dim retVal As Integer


Then set a path to the file you want to play. If you’ve seen my other MCI articles you should remember about adding “Quotes” around the path and filename, or at least supply the file’s short pathname.

        'The path to the movie or video to play.
        filename = "c:\movies\MyMovieFile.mp4"

        'Now add the quotes around the path.
        filename = Chr(34) & filename & Chr(34)

Next thing to do is open and setup a playback device. I usually use the MPEGVideo device since it works with audio and video. The MPEGVideo device is DirectShow down under.

There are a couple ways you can open the video. You can have it display in its own popup window or have it displayed in a control like a Panel or Frame. Basically any control with a .hWnd or .Handle property.

This command will display open a new device and have the video display in a control window.

'This code below will open a new mpegvideo device and play the movie in the “movieWindow” control which is
'nothing more than a GroupBox/Frame control I used in an example app. Basically any control with a
'handle can be used. For VB 6 you would use the controls .hWnd property instead of the
'Handle.ToInt32 property.
'If you want MCI to select which device to use just take out "type mpegvideo" from the code.

retVal = mciSendString("open " & filename & " type mpegvideo alias myMovie parent " _
& movieWindow.Handle.ToInt32 & " style child", vbNullString, 0, IntPtr.Zero)


If you want the video to open in a separate window use this code instead.

'Specify the mpegvideo driver to play the movies which should play most movie formats without any problems.
'This code will have the video open in its Own window and the alias name will be “myMovie”.
If you want MCI to select which device to use just take out "type mpegvideo" from the code.

retVal = mciSendString("open " & filename & " type mpegvideo alias myMovie", vbNullString, 0, IntPtr.Zero)

OK, now that you’ve opened a device, all you have to do is call the Play command to begin playback. The codes below will Play, Stop, Pause, and Resume.


 'Start Playing the movie once you’ve setup the device with your file.
 retVal = mciSendString("play myMovie", vbNullString, 0, IntPtr.Zero)



'Will Stop the playback if its currently playing.
 retVal = mciSendString("stop myMovie", vbNullString, 0, IntPtr.Zero)



'Will Pause the playback if its playing.
 retVal = mciSendString("pause myMovie", vbNullString, 0, IntPtr.Zero)



'Will Resume the playback if it has been paused.
retVal = mciSendString("resume myMovie", vbNullString, 0, IntPtr.Zero)


You want to use this code when your done with your device and/or closing your program so the mci resources will be cleaned up. You could change ‘close myMovie’ and put ‘close all’ to free everything MCI has used.

        'Will make sure the previous alias is destroyed. If the alias “myMovie” hasn’t been created yet,
        'this code will NOT cause any errors or anything. So there is no need to worry about that.
        retVal = mciSendString("close myMmovie", vbNullString, 0, IntPtr.Zero)

Well, that’s all there is to it. Hope you found something useful from this article. Have Fun!


Revised: 2015

Readymade Options for Playback of Music/Audio Files in VB and VB.NET – 2 of 2

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (21 votes, average: 3.81 out of 5)

I finally got time to finish part two about options available to play audio or music files using Visual Basic 6.0 and Visual Basic .NET. This article will provide info on two 3rd Party libraries for audio playback with advanced features. They are both feature rich and provide many  advanced features. The first is the Bass.Dll Sound System and the second is the FMod.dll Sound System.

Both libraries are Free to use as long as the application’s using them are not commercial or compensated. If its a personal or freeware application they grant you a free license to use them. Bass.dll does have a lower cost option if your making a Shareware app. You should read through the license agreements of each library before using them in your applications.

Note: You can check out part one at this link.

 BASS.DLL Audio System Library

This is a great library for pretty much all of your music or audio needs. Bass can play everything from mp3’s, wave’s and mod music to .cda’s and internet streaming. It has alot of source code and examples for Visual Basic and Visual Basic.NET. This library gives you access to the samples that are playing so you can plot your own visualizations or ffts. I had alot of experience with this library a few years ago and even made the original VB.NET api and examples for the author. The .dll is very small in size (Under 100KB) so it won’t bloat your application.

Author Information: BASS is an audio library for use in Windows and Mac OSX software. Its purpose is to provide developers with powerful and efficient sample, stream (MP3, MP2, MP1, OGG, WAV, AIFF, custom generated, and more via add-ons), MOD music (XM, IT, S3M, MOD, MTM, UMX), MO3 music (MP3/OGG compressed MODs), and recording functions. All in a tiny DLL, under 100KB* in size.

On Windows, BASS requires DirectX 3 or above for output, and takes advantage of DirectSound and DirectSound3D hardware accelerated drivers, when available. On OSX, BASS uses CoreAudio for output, and OSX 10.3 or above is recommended. Both PowerPC and Intel Macs are supported.

C/C++, Delphi, Visual Basic, and MASM APIs are provided, with several examples to get you started. .Net and other APIs are also available.

 Main Features Main features
Support for WAV/AIFF/MP3/MP2/MP1/OGG and custom generated samples
Sample streams
Stream any sample data in 8/16/32 bit, with both “push” and “pull” systems
File streams
MP3/MP2/MP1/OGG/WAV/AIFF file streaming
Internet file streaming
Stream data from HTTP and FTP servers (inc. Shoutcast, Icecast & Icecast2), with proxy server support and adjustable buffering
Custom file streaming
Stream data from anywhere using any delivery method, with both “push” and “pull” systems
Multi-channel streaming
Support for more than plain stereo, including multi-channel OGG/WAV/AIFF files
MOD music
Uses the same engine as XMPlay (very accurate, efficient, high quality reproduction), with full support for all effects, filters, stereo samples, DMO effects, etc…
MO3 music
MODs with MP3 or OGG compressed samples (vastly reduced file size with virtually identical sound quality), MO3s are created using the MO3 encoder
Multiple outputs
Simultaneously use multiple soundcards, and move channels between them
Flexible recording system, with multiple device support and input selection, (WMA encoding & broadcasting via the add-on, and other formats via BASSenc)
Decode without playback
Streams and MOD musics can be outputted in any way you want (encoded, written to disk, streamed across a network, etc…)
Speaker assignment
Assign streams and MOD musics to specific speakers to take advantage of hardware capable of more than plain stereo (up to 4 separate stereo outputs with a 7.1 soundcard)
High precision synchronization
Synchronize events in your software to the streams and MOD musics, synchronize playback of multiple channels together
Custom DSP
Apply any effects that you want, in any order you want
DirectX 8 effects Windows only
Chorus / compressor / distortion / echo / flanger / gargle / parametric eq / reverb, 2 implementation options each with its benefits (including mixing with DSP functions)
32 bit floating-point decoding and processing
Floating-point decoding/rendering, DSP, FX, and recording
3D sound
Play samples/streams/musics in any 3D position, with EAX support
Small buffers for realtime performance, large buffers for stability, automatic and manual buffer updating, configurable threading
Add-on system for additional format support and effects (C/C++ API available on request), dynamic plugin loading system, access to underlying DirectSound objects
BASS is less than 100KB*, so won’t bloat your distribution

As you can see, this is a very feature-rich and flexible sound system. If your interested in Bass.dll then go to the main webpage.

FMOD.dll Music and Sound Effects System

Continue reading

How to Open and Close the CDRom/DVDRom Tray Door using VB and VB.NET

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (18 votes, average: 4.00 out of 5)

Opening or closing the optical disk drive(ODD) tray door in any Visual Basic and Visual Basic.NET language is easy to do thanks to the Windows API. This article will be using code based on the MCISendString Api which I made a complete tutorial for starting MCI. Click this link to check it out.

These codes are setup for VB.NET but all you have to do is change Integers to Longs which will then work pefectly fine with Visual Basic 6.0.

So the first thing you’ll want is this API call…


    'Api call to send the commands to the mci device
    Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As _
        String, ByVal lpstrReturnString As String, ByVal uReturnLength As Integer, ByVal hwndCallback As _
        Integer) As Integer

VB 6.0

    'Api call to send the commands to the mci device
    Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As _
        String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As _
        Long) As Long


Now just need to send the commands.

The code below will open and close the default CD/DVD Door and you won’t need to set/specify the ODD drive path.

'Pop it open
mciSendString("set cdaudio door open", 0, 0, 0)

'Shut it
mciSendString("set cdaudio door closed", 0, 0, 0)



Use the codes below will setup and use the variables and the specified alias you want to use.

        'This will simply get the api call return value that can be used if you use the MCIGetErrorString API.
        'This example won’t be using that API though.
        Dim retVal As Integer

        'This will contain the drive you want to open. Ex: D:\ or E:\ or whatever.
        Dim cdDrive As String
        'Now setup the path to your computers cd or dvd drive you want to open or close.

        'Remember to put Quotes around any path you pass to the mci device.
        'Also specify the correct drive letter for the CD/DVD Drive.
        'I’m using drive “D:” which is the location of the DVD/CDRom on my computer.
        'You can specify the drive path like ‘D:’ or ‘D:\’
        cdDrive = Chr(34) & "d:" & Chr(34)

        'Now its time to setup the MCI Device using the CDAudio driver.

        'First setup a new device using the CDAudio driver with alias named “cd”.
        retVal = mciSendString("open " & cdDrive & " type cdaudio alias cd wait shareable", 0, 0, 0)

        'Now that the MCI Device is programmed and ready to go, you can start sending it commands.
        'The codes below will Open the CD or DVD Tray Door and Close the CD/DVD Door…

        'This will Open the door.
        retVal = mciSendString("set cd door open", 0, 0, 0)

        'This will Close the door.
        retVal = mciSendString("set cd door closed", 0, 0, 0)

Thats all there is to it! If the code executed properly, your optical drive should have opened and/or closed. The code here will work with all VBs and VB.NET languages.

Just Change all Integer types to Long types if your using VB 6.0.

If your wanting to make a complete CD Player application, I have complete libraries for both VB 5/6 and Visual Basic.NET at my Visual Basic Code Source website. Anyways, have fun!


Counters/Timers for the Visual Basic and VB.NET programmer

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (6 votes, average: 4.50 out of 5)

This article can be applied to all versions of VB including 6.0. Any code that may be posted here is originally set up for the .NET, but codes should be compatible with VB 6.0 by changing the variables and the declares to the right type and format. Example: If something is set to type Integer for .NET, the equivalent in VB 6.0 is Long. Otherwise, most of the .NET code should work fine in 6.0. The only trouble you may have is using 64 Bit Integers, which Classic VB doesn’t quite support. A work-around it using the Currency type (Which is technically a 64 Bit type) and converting it to a string while removing the decimal point. Check out this page for how to use the 64-bit Currency type in VB 6.0

Timers/Counters Info

This question on what timers are available using Visual Basic has a somewhat simple answer. Well, depending on the resolution you need to have.

GetTickCount – The “GetTickCount” function has a resolution of about 15-16(ms). IT returns the amount of milli-seconds that has elasped since your Windows OS has started.

    'Provides about a 16(ms) resolution.
    Private Declare Function getTickCount Lib "kernel32" Alias "GetTickCount" () As Integer

timeGetTime – If you need better accuracy, then you can try the multi-media timer: “timeGetTime” function, which can have a resolution of about 1(ms). It likewise returns the number of milli-seconds that has elasped since your Windows OS was started. But is has a much better resolution compared to the tick count function.

    'Provides a resolution of 1(ms).
    Private Declare Function timeGetTime Lib "winmm.dll" () As Integer

QueryPerformanceCounter – But, what if you need even better accuracy/resolution? The next option would be to use the computers high “Performance Timers”. (To check if the target computer actually supports this hardware timer, you would call either of the performance functions and look at its Return Value. If the return value is “0”(Zero), then the computer doesn’t support the hardware counter/timer feature. Not much more to say about this except you won’t be able to use this option.)

These functions are: ‘QueryPerformanceCounter’ and ‘QueryPerformanceFrequency’. With these functions its possible to get Sub-Millisecond accuracy/resolution. These timers could use a very small chip on your computers motherboard, which usually has a frequency of about: 3.6 Mhz. In some probably rare accurances these functions will actually use the RDTSC timestamp of your computers Processor. This would obviously have the highest resolution of all the timers in the computer. You can measure time in actual CPU Cycles. But i’ve rarely had this timer use that processor feature. In fact, I only witnessed it one time using my CPUs ReaDTimeStampCounter register. This would vary from computer to computer though. Microsoft says these functions could use either of these counters. * To determine which feature this counter/timer is using, you can use the function: QueryPerformanceFrequency function. This function returns the TickPerSeconds for the Performance Counter. Probably the most common value would be: 3579545. Which means that every second, this timer ticks 3,579,545 times, or around 3.6 million cycles per second. IF you have a 2ghz cpu/processor, and it is using your cpu’s rdtsc register, then the return value would be around the clockspeed of your processor.

    'Gives you the current tick counts for the cpu since the computer has been running.
    'You could get very high resolutions in the Sub-Millisecond range with this counter/timer.
    Private Declare Function QueryPerformanceCounter Lib "kernel32" (ByRef counts As Long) As Integer
    'Returns the frequency of the performanceCounter in counts-per-second.
    Private Declare Function QueryPerformanceFrequency Lib "kernel32" (ByRef frequency As Long) As Integer

RDTSC Register – This is a feature of all modern AMD/Intel CPUs/Processors since the original Pentium 1 was released. This timer ‘Ticks’ every time your Processor completes a ‘Cycle’. As you can probably discern, you can have some major high resolution timing available. But the big problem for getting to this timer if that its pretty much not possible to access this register on the CPU with the high level languages of Visual Basic and C#. But, if you can do a somewhat simple C++ DLL application, you can access this register and create a function in the .dll that will return the value of that timer when Visual Basic calls that .dll function. This is actually what I did with my: csRDTSC.dll I made with C++. IF you would like to use this .dll, just goto my main: webpage and under either the Classic or DotNET controls section page you can download and use it. The zip file includes the actual .DLL and a text file with the available functions.

Reference Information

Here is some reference links here that are related to these timer functions that would be more helpful.

QueryPerformanceCounter Reference…

Overview: QueryPerformanceCounter Function

How To: Time Managed Code Using QueryPerformanceCounter and QueryPerformanceFrequency

timeGetTime Reference

Multimedia Timer Reference – Overview of the timeGetTime related timers as
timeGetTime – The timeGetTime function retrieves the system time, in milliseconds. The system time is the time elapsed since Windows was started.

GetTickCount Reference…

GetTickCount Function

GetTickCount64 Function

How To – Retrieve Elapsed Time Since Windows Started


I really do hope you can get something useful from this small and brief article. I have many examples on my main webpage at: which shows how to use these timers. I even have a VB.NET – Example that compares the 3x most common timers that I outlined above. I also have a example for all of the Visual Basic versions (including Visual Basic.NET) that shows how to use my csRDTSC.DLL to get the time stamp value from the cpu and to calculate your processors clockspeed. Anyways, have fun 🙂


Minor Revision: 2015

How to Create/Make a String Buffer using VB.NET and VB 6.0

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (7 votes, average: 4.57 out of 5)

This is a simple tip on how to create a string buffer with a specific number of spaces. The code in this article will create a string with a 128 spaces or buffer size.

The traditional way a lot of the VB 6.0 programmers used to created a string variable with a specific size buffer as shown below, is not supported in .NET.

'This method works just fine with Classic VB (5.0/6.0), but Visual Basic.NET unfortunately
'does not support this somewhat traditional string buffer code.
Dim buf As String * 128

That code will create the string variable “buf” with a buffer of 128 spaces. IF you try running that code in Visual Basic.NET, then you should get a “End of statement expected.” Error.

There is another way, that I use even with VB 6.0 which will work with VB.NET as well. That is by using the Space (Space$) Function.

Public Function Space(ByVal Number As Integer) As String

The Space() Function will return a String with a buffer size that you specify. If your using Visual Basic 6.0 then use the Space$() Function which will return the value as an actual String. String$ is supported in .NET but the Space() returns a String variable no matter which format you use.

'Visual Basic.NET AND Visual Basic 6.0 supports this way of creating a String with
'a specific sized buffer.
Dim buf AsString

buf = Space(128)
'This should throw a message with the size of the buffered string variable.
MsgBox(Len(buf), MsgBoxStyle.OKOnly, " The size of the String")

Results of the codes above

That’s all you have to do in DotNET and 6.0 to make a String buffer. This code will work in all versions of VB.NET, Visual Basic 2008, VB 2010, and newer.

Anyways, hopefully this small little tip helped 🙂


Revised: 2015

Microsoft Interop Forms Toolkit 2.1

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)

I meant to post this page along time ago and forgot I made it. So here it is, even though its quite late. Anyways, Below is a preview of the new Interop User Controls that can make it much easier to deal with and interop with the Classic versions of Visual Basic 5.0 and Visual Basic 6.0. Here is the link to the msdn page…

Bring the Power of .NET to Visual Basic 6

The Interop Forms Toolkit provides tools and components that simplify the process of building forms and controls with Visual Basic .NET that can be easily consumed from Visual Basic 6. All the required COM interop components can be created with the click of a button, allowing you to quickly create powerful hybrid applications. The Toolkit makes it easy to expose .NET form methods, properties, and events to Visual Basic 6. In addition, functionality is provided to share application state and signal application-level events.

New in Version 2.0 – Interop UserControls

Interop UserControls allow you to host any .NET control on a Visual Basic 6 form as if it was a real ActiveX control.  This means you can extend your existing Visual Basic 6 applications by taking advantage of the rich library of controls that .NET has to offer.

In the image below, you can see a standard Visual Basic 6 form hosting a .NET ToolStrip and a MenuStrip. Creating these controls in Visual Basic 6 would be extremely time-consuming, but by using .NET these controls can be added in seconds!

These controls can also be placed on MDI forms, which the previous version of the Toolkit did not support. Other new features include a redistributable package for easier deployment, RegFree COM support for Interop UserControls, and substantially improved documentation.

Interop Forms

Here we see a Visual Basic 6 Application (Orders) that launches a .NET form as a Customer lookup screen. The .NET form was quickly created using drag and drop from the Data Sources window, and can easily make calls to a Web service.

Leverage Your Visual Basic 6 Investments

The toolkit allows you to preserve your Visual Basic 6 applications and add functionality to them through additional .NET forms. For example, you could provide more dynamic content by adding a WinForm that accesses Web services or RSS feeds. You could create lookup dialogs faster using .NET’s Data Sources Window. ClickOnce Deployment allows you to deploy the entire application (both the Visual Basic 6 part and the .NET part).

Wrap Existing .NET Projects

Although the toolkit provides templates to get you started, you can also expose your existing .NET Forms to Visual Basic 6. Just load your forms into a Class Library, and click on “Generate InteropForm Wrapper Classes” and the tool will create the required COM wrappers.

Fully Extensible

With an extensible architecture and Full Source Code Available, it’s easy to customize the toolkit to your specific requirements.

  • Interfaces: All of the core toolkit services have interfaces defined which you can use to create your own implementations
  • Inheritance: All of the core toolkit services are inheritable and the behavior is overridable
  • Partial Classes: The add-in generated code can be extended via partial classes

If your interested in these Interop UserControls, then head over to the MSDN page. Have fun!


Revised: 2015

Performing Basic Math in Visual Basic and Visual Basic.NET (Updated!)

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (4 votes, average: 4.25 out of 5)

Its actually easy to do basic math in Visual Basic 5.0/6.0 and Visual Basic.NET 2002/2003 and Visual Basic 2005. Both the VB 5.0/6.0 and .NET Framework has a Math Class/Module to perform more advanced calculations. Unfortunately I do not know much beyond the scope of basic Math calculations, so don’t expect anything beyond the basics.

Update: Since many are apparently wanting to make a calculator based application I added a new link to a Tutorial for VB .NET on making a basic calculator. The link is with the other VB calculator example links near the bottom of this post.


Operators for Basic Math

  • + = Addition
  • – = Subtraction
  • * = Multiply
  • / = Division *ForwardSlash is More Exact, Includes Decimal Remainders
  • \ = Division *BackSlash Returns Integers only with No Decimals/Remainders

To perform basic math is easy with any version of VB. You can perform Math on variables and/or actual numbers…

Note: In Visual Basic 5.0 and Visual Basic 6.0 you should change the .NET Codes in this article from Integer types to Longs.

Dim myMath As Integer

myMath = 2 + 2


 The Messagebox will return the number ‘4’ since it added ‘2 + 2?. Adding actual variables it just as easy…

        Dim myMath As Integer

        Dim myMath2 As Integer

        myMath = 2

        myMath2 = 5

        MsgBox(myMath * myMath2)

The first message with the forward slash includes the remainder or decimal portion and the back slash will return the integer number ‘2’ with no decimal. So, the first messagebox returns = ‘2.4’ and the Second message box returns = ‘2’…

Subtraction was just as easy. Just use the Dash – operator as the example does above. The message box above returns = ‘7’ since ’12 – 5 = 7?.

You can also perform calculations on String variable types. You use them similar to the number based types. I would recommend using the Val() function in Visual Basic. Val will return or convert the Integers in a String to Doubles that is better to do when you are working with numbers as values to be calculated. Even if the String contains a non-number value along with a number value, Val() will try to convert the characters to a number value. Example…

        Dim myMath As String

        Dim myMath2 As String

        myMath = "12k"

        myMath2 = "5j"

        MsgBox(Val(myMath) * Val(myMath2))

The messagebox above will return a ’60’ since Val() only cared about the Interger characters and not any non-number based values.

If your interested, I have both a VB 6.0 and VB.NET 2005/2008 Example of how to make a basic calculator application. Click Here for the Classic VB Example and Click Here for the VB.NET 2005/2008 Example.

Update: Click this link if you want to view a tutorial on specifically making a basic calculator via Visual Basic .NET.

As you can see, performing basic math is very easy to do. There are other Functions in Visual Basic as well like Sqr (Sqrt in .NET), Sin, Cos, and more. But that is beyond the scope of this article. Maybe at another time. Anyways, Have Fun!


Revised: 2014

Auto Complete Support in Textbox and Combobox Controls using VB 6.0 and VB.NET

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (3 votes, average: 2.00 out of 5)

Autocomplete is a very useful feature that Microsoft added with the release of Internet Explorer 5.0 and therefore Internet Explorer 5.0 or higher needs to be installed on the target computer. Adding autocomplete to your applications can be a real benefit to the user and is a easy feature to implement.

Note: Visual Basic 2005 and Visual Basic 2008 already has Autocomplete capabilities in the Textbox and Combobox controls by default.

There are a few different locations you can get the autocomplete data from…

  • File System
  • History List
  • URLs Recently Used
  • ALL URLs
  • ALL System Sources

There are likewise a few different options available to set the way you want AutoComplete to react.

  • Append
  • Suggest
  • Append & Suggest

Visual Basic.NET

    'The API call that enables the autoComplete feature to your combo or textbox controls.
    Private Declare Sub SHAutoComplete Lib "shlwapi.dll" (ByVal controlHandle As Int32, ByVal _
        completeFlags As Int32)

Visual Basic 6.0

    'The API call that enables the autoComplete feature to your combo or textbox controls.
    Private Declare Sub SHAutoComplete Lib "shlwapi.dll" (ByVal controlHandle As Long, ByVal _
        completeFlags As Long)

The SHAutoComplete API Sub is easy to use. The first parameter is the Handle to the Edit (Combobox/Textbox) control you want to enable Auto Complete too. The second Parameter is how you want your Autocomplete to react and display.


    'Various Flags you can set to be the source.
    Private Const Defaults = &H0

    Private Const Filesystem = &H1

    Private Const HistoryList = &H2

    Private Const URLRecentlyUsedList = &H4

    Private Const AllURLs = (HistoryList Or URLRecentlyUsedList)

    Private Const AllSystemsSources = AllURLs Or FileSystem

The flags below are used to specify how you want your autocomplete feature to react.

    'Flags you can use to specify how your want autocomplete to react.
    Private Const append = &H40000000 Or &H20000000

    Private Const suggest = &H10000000 Or &H80000000

    Private Const suggestAppend = &H40000000 Or &H10000000

Now that the API based codes are out of the way, you can setup the edit based controls (Like Textbox and Combobox) to have Autocomplete capabilities. Below is a simple example of adding autocomplete to a textbox control that I named txt.

        'Set autocomplete to the textbox using the system defaults.
        SHAutoComplete(txt.hWnd, Defaults)

        'You can also specify how it will react and what it will display.
        SHAutoComplete(txt.hWnd, suggest Or AllURLs)

If your using .NET, just change txt.hWnd to txt.Handle.ToInt32.

Unfortunately adding this feature to a Combobox isn’t as straight forward. Thats because when you use the Handle/Hwnd Property for the Combobox it returns the Main Window Portion of the control and NOT the Edit Window portion. There are a couple ways to get around this though. One way it to use the GetComboBoxInfo API or to use the FindWindowEx API call. I chose to go ahead and use the FindWindowEx API.

Visual Basic.NET

    'API Function used to get the Edit window of a combobox control.
    Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As  _
        Int32, ByVal hwndChildAfter As Int32, ByVal lpszClass As String, ByVal lpszWindow As String) As Int32

Visual Basic 6.0

    'API Function used to get the Edit window of a combobox control.
    Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal handle As _
        Long, ByVal hwndChildAfter As Long, ByVal lpszClass As String, ByVal lpszWindow As String) As Long

Now you just need to use the FindWindowEx Function using the 1st and 3rd parameter. And once you call the FindWindow function, simply pass its return value to the SHAutoComplete Method.

        'Simply change this variable type to a Integer if your using VB.NET.
        Dim cmbHandle As Long

        'Retrieve the handle to the ‘Edit’ Window of the combobox. I named my Combobox control cmb.
        cmbHandle = FindWindowEx(cmb.hWnd, 0, "Edit", vbNullString)

        'Activate Autocomplete to the combobox edit window.
        SHAutoComplete(cmb.hWnd, Defaults)

Tip: Here is how you can specify exactly how to react and display….

        'You can also specify how it will react and what it will display.
        SHAutoComplete(cmb.hWnd, suggest Or AllURLs)

Again, change cmb.hWnd to cmb.Handle.ToInt32 if your using Visual Basic.NET.

Thats all there is to it! Depending on your application, you or your apps user will really appreciate you putting that feature in your program. Well, I guess there is nothing more to add. Have fun!


Calculate and Get the Computers CPUs/Processors System Usage with Visual Basic and VB.NET

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (5 votes, average: 3.80 out of 5)

There are many reasons for wanting to get the CPU’s/Processor’s usage values. Especially for code profiling and testing. There are a couple limitations if you use this code. The GetSystemTimes() API function requires the target computer to have Windows XP with Service Pack1 and higher Operating System installed. The other is it will return the cpu usage (processor usage) based on ALL of the systems processors. Example: If the target computer has 2x CPU’s (or Cores) and one of the processors is 100% but the other cpu is 0%, then it will return 50% as the total cpu usage. Otherwise there is nothing to worry about.

Visual Basic 6.0


'This API Call "Requires" Windows XP with Service Pack 1 or Higher Operating System.

'More Info:

Private Declare Function GetSystemTimes Lib "kernel32.dll" (ByRef idleTime As _
    Currency, ByRef kernelTime As Currency, ByRef userTime As Currency) As Boolean
'Will be used to cause the applications thread to 'Sleep' or Pause/Timeout for a
'specified number of Milli-Seconds.
Private Declare Sub Sleep Lib "kernel32" (ByVal millisecondsToSleep AsLong)
'This variable is used to specify how often to check and display the CPU Usage value.
Dim updateSpeed As Long


Visual Basic.NET, Visual Basic 2008, and 2010


'This API Call "Requires" Windows XP with Service Pack 1 or Higher.

'More Info:

Public Declare Auto Function GetSystemTimes Lib "kernel32.dll" (ByRef idleTime As _
    Int64, ByRef kernelTime As Int64, ByRef userTime As Int64) As Boolean

'This variable is used to specify how often to check and display the CPU Usage value.

Dim updateSpeed As Integer = 250

Next we need to get the IdleTime, KernelTime, and the UserTime numbers from the GetSystemTimes() API Function. In order to get the actual cpu’s total system usage you will need to calculate the Time values from when you first got the Get System Times API and then a timeout of some sort (Its possible the longer the timeout the more accurate). After the timeout period you will want to get the values from the Get System Times() API call one more time.

Note: Since the code will take up a lot of space, I will just add the code for Visual Basic 6 for now. All you really need to do to make it work in .NET is change the variable types.

Changes to make the code below to be compatible with .NET

  • Change the Visual Basic 6.0 Long types to Integer types
  • Change the VB 6 Currency types to Long types (or Int64)
  • Change the Sleep command to the Threading.Thread.Sleep method.
  • Change Doevents() to Application.DoEvents()

Visual Basic 6.0

First you need to make 3x variables to get the first results from the GetSystemTimes api, then 3x more variables to get the GetSystemTimes values after the timeout/sleep period, and then 3x more to hold the values from subtracting the first results from the second results. (Second – First)

'These are to hold the starting times values.
Dim sIdle As Currency
Dim sKernel As Currency
Dim sUser As Currency
'These variable are to hold the ending times values.
Dim eIdle As Currency
Dim eKernel As Currency
Dim eUser As Currency
'These will hold the values that are calculated from the ending and starting times.
Dim cIdle As Long
Dim cKernel As Long
Dim cUser As Long

Once thats taken care I created 2x more variables for calculating purposes…

'This variable will contain the values of cKernel + cUser.
Dim systemTime As Long
'Will contain the calculated cpu usage as a percent value.
Dim totalCpuUsage As Double

All thats left now it to call the Get System Times API before and after the timeout, add the kernel and user results together, and finally calculate the cpu usage values and display them in a label control that I named: lblUsage.

Note: You can put the code below inside a Loop, or in a Timer control.

'Retrieve the Times values before starting the delay.
GetSystemTimes sIdle, sKernel, sUser
sIdle = Val(sIdle)
sKernel = Val(sKernel)
sUser = Val(sUser)
'The delay for how often to check and update the cpu usage values.
'Note: You can use the sleep api if you want or the simple pause sub I added.
'Retrieve the Times values after the Delay.
GetSystemTimes(eIdle, eKernel, eUser)
eIdle = Val(eIdle)
eKernel = Val(eKernel)
eUser = Val(eUser)
'Get the values calculated between the starting and ending Times values.
cIdle = (eIdle - sIdle)
cKernel = (eKernel - sKernel)
cUser = (eUser - sUser)
'Calculate the total system time. Which is Kernel and User time together.
systemTime = (cKernel + cUser)
'Now calculate the values as a percentage based number.
totalCpuUsage = (systemTime - cIdle) * (100) / (systemTime)
'Simply display the calulated results in a label control.
lblUsage.Caption = "Total CPU Usage: " & (totalCpuUsage) & "%"

CPU Usage Example using GetSystemTimes()

That’s all there is to it!  Have fun!