devxlogo

Tip Bank

The status of shift keys

Visual Basic lets you test the state of the Shift, Alt and Ctrl keys only within the KeyUp, KeyDown and all the mouse-related event procedures. If you want to test

Never use the GetLastError API function

If you heavily use API calls and strictly follow the SDK documentation, you might be tempted to use the GetLastError API to retrieve the error returned by your last API

Change caret size and blink rate

You can alter the size of the caret (this is the name of the cursor within text boxes, not to be confused with the mouse cursor), for instance to ease

WindowsVersion – The version number of the operating system

Private Type OSVERSIONINFO dwOSVersionInfoSize As Long dwMajorVersion As Long dwMinorVersion As Long dwBuildNumber As Long dwPlatformId As Long szCSDVersion As String * 128End TypePrivate Declare Function GetVersionEx Lib “kernel32” Alias

Enum constants that include spaces

If you’re writing an ActiveX control, you can create properties that return an enumerated value, as in: Public Enum SizeConstants SizSmall = 1 SizMedium SizLargeEnd EnumPublic Size As SizeConstants When

Beware of Defxxx directives

Every now and then I see DefInt or DefLng directives spread over Visual Basic code modules, whose intended purpose is to revert the default data type from Variant to Integer

Hidden Variant variables

Variants are the default type of variables that are declared without an As clause, as in: Dim name ‘ this is a variant or are not declared at all (which

Use DataChanged with unbound controls

When you need to learn if a field has been changed by the user, you have at least three options: you can use a global boolean variable and set it