Learning MicroStation VBA

Chapter 32: Using the Windows API

We added references to things such as the "Microsoft Scripting Runtime," "Microsoft ActiveX Data Objects," "Microsoft CDO for Windows 2000" and so forth. When we did this, we had instant access to functionality not natively exposed to VBA.

Although working with the Windows API is not as simple and straight forward as adding a reference, the process is fairly painless and the results can be powerful.

Declaring API Calls

You can declare Windows API calls in the General Declarations area of a code module. Once declared, use the API calls as you would use any other function or procedure.

Here is an example:

Public Declare Function <b class="bold">Beep</b> Lib "kernel32" (ByVal dwFreq As Long, _                                 ByVal dwDuration As Long) As Long

The function name in the above declaration is "Beep." It is an amazing API call that beeps. It beeps as long and as high (or as low) as we ask it to. You find API functions and procedures inside DLL (Dynamic Link Library) files. This one is inside the kernel32.dll file. Let's try it out, shall we?

After declaring the Beep function in the General Declarations area of a code module, we can use it as follows:

Sub <b class="bold">TestBeep</b>()    Beep 4000, 250    Beep 2000, 250    Beep 1000,...

UNLIMITED FREE
ACCESS
TO THE WORLD'S BEST IDEAS

SUBMIT
Already a GlobalSpec user? Log in.

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.

Customize Your GlobalSpec Experience

Category: Device Drivers
Finish!
Privacy Policy

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.