devxlogo

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

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

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

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

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

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

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

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

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

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

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

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.

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

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

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

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

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 =

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

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

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

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

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)

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

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

Create stand-alone type libraries

Many VB programmers assume that Visual Basic 5.0 is not capable of creating stand-alone Type Libraries, because the documentation states that when an ActiveX component or control is created, the

Passing Public class variables by reference

Under VB4 Public variables in form and class modules were implemented in the same manner as variables in BAS modules, that is, as direct references to memory locations. This allowed

Properties of Static Storage

Global objects, static data members of a class, namespace variables, and static variables in functions reside in static memory. Static objects are allocated by the linker and their address remains

Using the Bulk Copy Program Properly

The Bulk Copy Program is still a handy utility for transferring data in and out of tables in SQL. However, using it properly requires that you learn the various command

Specifying the Locale

Closely related to the issue of internationalization is the java.util.Locale class. An instance of Locale represents a geographic, political, or cultural region, and may or may not correspond to a