We are an award-winning tech entrepreneurship website where trusted experts can provide value globally.

Since 1998, DevX has helped people start businesses, build websites, and provide enterprise technology to people globally. Interviewing the likes of Microsoft’s co-founder, Steve Ballmer, the publication brings comprehensive, reliable, and accessible insights to the Internet.

devxlogo

Trusted for 26 years

Over 30K Articles

1M+ Readers

Expert-reviewed

10K+ Tech Terms

As seen in:

microsoft logo
business_insider_logo
wired_logo
berkley
arstechnica_logo
hackernoon

The Latest

DevX - Software Development Resource

Short-circuit evaluation with Select Case

Short-circuit evaluation is an optimization technique automatically adopted by most modern compilers, including all flavors of C++, Borland Delphi and many others. Unfortunately, the Visual Basic compiler is not in

DevX - Software Development Resource

Create a GUID

When you build your ActiveX controls and components, Visual Basic automatically creates all the GUIDs as necessary. The same also happens in other cases, without you even realizing it: for

DevX - Software Development Resource

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

DevX - Software Development Resource

ByVal with object references

When you write a procedure and you want to be sure that the procedure does not affect the value of any variable passed to it as an argument in the

DevX - Software Development Resource

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

DevX - Software Development Resource

Convert Hexadecimal numbers

While Visual Basic offers the Hex$ function that converts a decimal value into its hexadecimal equivalent number, it seems that the inverse function is missing. Not true. Try out this

DevX - Software Development Resource

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

DevX - Software Development Resource

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

DevX - Software Development Resource

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

DevX - Software Development Resource

Overwrite mode for textbox controls

By default, textbox controls work in insert mode, where each new character never overwrites existing ones. If you wish to implement overwrite mode you can take advantage of the fact

DevX - Software Development Resource

Missing Option Explicit directives

The single statement that is most useful to avoid bugs is Option Explicit. Always use it in every module of your applications. Even better, let the Visual Basic IDE automatically

DevX - Software Development Resource

HiWord – The most significant word in a Long value

Private Declare Sub CopyMemory Lib “kernel32” Alias “RtlMoveMemory” (dest As _ Any, source As Any, ByVal bytes As Long)’ Return the high word of a Long value.Function HiWord(ByVal value As

DevX - Software Development Resource

SystemDirectory – The path of the System directory

Private Declare Function GetSystemDirectory Lib “kernel32” Alias _ “GetSystemDirectoryA” (ByVal lpBuffer As String, _ ByVal nSize As Long) As Long ‘ The path of the System directoryFunction SystemDirectory() As String

DevX - Software Development Resource

Benchmarks with millisecond accuracy

The Timer function returns a value which is only accurate to about 55 milliseconds, therefore it is not very useful for doing accurate benchmarks. If you need a better resolution

DevX - Software Development Resource

WindowsDirectory – The path of the Windows directory

Private Declare Function GetWindowsDirectory Lib “kernel32” Alias _ “GetWindowsDirectoryA” (ByVal lpBuffer As String, _ ByVal nSize As Long) As Long’ Return the path of the Windows directoryFunction WindowsDirectory() As String

DevX - Software Development Resource

UserName – The name of the interactive user

Private Declare Function GetUserName Lib “advapi32.dll” Alias “GetUserNameA” _ (ByVal lpBuffer As String, nSize As Long) As Long’ The name of the interactive userFunction UserName() As String Dim buffer As

DevX - Software Development Resource

Property Procedures in BAS modules

Visual Basic supports Property procedures to implement properties in your own CLS and FRM modules. However, it turns out that you can use Property procedures even within BAS code modules.

DevX - Software Development Resource

Storing objects in the Tag property

The Tag property exposed by many Windows Common Controls (including TreeView’s Node objects and ListView’s ListItem objects) is more versatile than the ListBox and ComboBox controls’ ItemData property, because it

DevX - Software Development Resource

Multiple compilation constants

Visual Basic’s documentation does not explain how to specify more than just one conditional compilation constant in the Advanced tab of the Options dialog. The correct way is using a

DevX - Software Development Resource

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

DevX - Software Development Resource

Don’t use SetFocus on invisible controls

In the Show event of a form you might be tempted to use SetFocus to select which field the end user should begin working with. However, this method raises an

DevX - Software Development Resource

Load a text file in one operation

The fastest way to read a text file is using the Input$ function, as shown in this reusable procedure: Function FileText (filename$) As String Dim handle As Integer handle =

DevX - Software Development Resource

Fixed-length strings allocate and deallocate faster

Fixed-length strings are generally slower than conventional strings, because all VB string functions and operators only recognize conventional strings, thus all fixed-length strings must be transparently converted to and from

DevX - Software Development Resource

Enhanced For-Next loops

At times you may need to execute the same block of statements for different values of a variable, but you can’t use a straight For Next loop because the sequence

DevX - Software Development Resource

IsMissing returns False with non-Variant arguments

Every now and then I forget that the IsMissing function always returns False when the argument is not a Variant value. This happens because IsMissing does nothing more than converting

DevX - Software Development Resource

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

DevX - Software Development Resource

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)

DevX - Software Development Resource

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

DevX - Software Development Resource

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