
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.
Don’t use an empty For…Next loop to add pauses to your programs; instead, use the Sleep API function, that releases the CPU and lets other apps in the system effectively
In VB applications compiled as native code, GoSubs are 5-6 times slower than calls to regular Subs or Functions; conversely, in p-code they are considerably faster. This is one of
OK, this is a silly suggestion, but I personally know a lot of developers that complain about Visual Basic’s bugs that were fixed in more recent Service Packs. This is
Use the And operator instead of Mod when the divisor is a number in the form 2^N. For instance, there are two methods to extract the least significant byte in
‘ ShellSort an array of any type” ShellSort behaves pretty well with arrays of any size, even’ if the array is already “nearly-sorted”, even though in’ particular cases BubbleSort or
If your application uses objects from external components, either third-party or your own libraries, a good rule of thumb is to include the complete servername.classname string in the Dim statement,
The StartLogging and LogEvent methods of the App object only work in compiled applications. This behavior is by design and shouldn’t be considered a bug, even though it isn’t documented
You can’t reliably test an auto-instancing object variable using the Is Nothing test, because as soon as you reference the variable Visual Basic silently creates an object of the given
‘ Returns the name of the current project’ The first time it’s called it clears the error code’Function ProjectName() As String Static result As String If Len(result) = 0 Then
‘ Return the string of code the is selected in the code window’ that is currently active. ‘ This function can only be used inside an add-in.Function GetSelectedText(VBInstance As VBIDE.VBE)
‘ Test whether a font name and size is supported’ Returns True if the font is supported, False otherwise” If the font is supported but the size is not, it
‘ Returns the integer equal or higher than its argumentFunction Ceiling(Number As Double) As Long Ceiling = -Int(-Number)End Function
Private Declare Function GetSystemMetrics Lib “user32” (ByVal nIndex As Long) _ As Long’ Returns True if a Network is found (read-only)Function IsNetworkInstalled() As Boolean Const SM_NETWORK = 63 IsNetworkInstalled =
Use “” instead of “/” when performing divisions between Integers. The “/” operator returns a Single value, therefore the seemingly efficient line C% = A% / B% actually requires three
Every now and then someone asks me “How can I modify the default description that is associated to an add-in I have written and that appears in the Add-In Manager?
Don’t fill your code with unnecessary DoEvents statements, especially within time-critical loops. If you can’t avoid that, at least you can reduce the overhead by invoking DoEvents only every N
‘ Binary search in an array of any type’ Returns the index of the matching item, or -1 if the search fails” The arrays *must* be sorted, in ascending or
‘ The number of 1’s in a binary number” This routine is based on the following property ‘ of binary numbers: n And (n-1) always clears the’ least significant “1”
Private Declare Function GetShortPathName Lib “kernel32” Alias _ “GetShortPathNameA” (ByVal lpszLongPath As String, _ ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long’ Convert a long filename into the
If you haven’t switched to DCOM yet, and still use Remote OLE Automation, you must launch the Automation Manager program on the server machine, in order to let the server
This is an evergreen, but it’s still popular. It is very easy to create a window that always stays on top of the others, thanks to the SetWindowPos API function.
We all know to keep the sa password secret and to share it with as few people as necessary. However, users see no problem with registering their server in Enterprise
The const qualifier guarantees that the value of an object cannot be changed directly by the program. However, it may be altered asynchronously–that is, by a way unknown to the
You may already know how to replace the default gray form submit button with an image (see Tip “Replace Form Buttons With Images”), but do you know how to replace
The default behavior for a java.awt.TextArea is to scroll the text you enter to the left once the length of the line of text exceeds the displayable area. When this
When you need to process each character in a string, you can assign the string to a byte array and iterate on its elements (remember: each Unicode character corresponds to
Sometimes you want to know if the desktop is in Active Desktop mode-for example, to set an HTML wallpaper. I couldn’t find a function to accomplish this, but this hack
At times, you might want to retrieve the current system font settings, such as the font being used for window title bars, or the menu or message box font. You
When using bound controls, data is updated automatically when you Move to a different record. Data is not updated when you close the form. To ensure that data is saved
When debugging Java Database Connectivity (JDBC) problems, it can be difficult to locate the source of errors. However, one facility that can be used to accomplish this is the logging/tracing

