devxlogo

Tip Bank

Caution when moving or resizing forms

Any action that affects a form’s size or position should be inhibited when the form is minimized or maximized, because this causes a runtime error 384. Always double check your

Determine how a control got the focus

At times it might be convenient to know how a given control got the focus, namely by means of the Tab key, an associated hotkey or a click of the

The status of mouse buttons

Visual Basic lets you test the state of mouse buttons only inside a MouseDown, MouseMove, or MouseUp event procedure. To determine the current state of mouse buttons you can use

ComputerName – The name of the local computer

Private Declare Function GetComputerName Lib “kernel32” Alias _ “GetComputerNameA” (ByVal lpBuffer As String, nSize As Long) As Long’ Returns the name of the computer.Function ComputerName() As String Dim buffer As

Interpreted or Compiled?

It is highly unfortunate that Visual Basic doesn’t offer a way to execute a group of statements only when the program is interpreted in the environment or only when it

IsWindowsNT – Check Windows platform

Private Declare Function GetVersion Lib “kernel32” () As Long’ Returns True is executed under Windows NT,’ False if executed under Windows 95/98Function IsWindowsNT() As Boolean IsWindowsNT = (GetVersion() And &H80000000)

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

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