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

Use the MS Draw Applet to Draw Lines and Shapes

Rather than using Visual Basic’s line and shape objects when drawing complex graphic backgrounds on forms, use the MS Draw applet included with most Microsoft products to draw a Windows

Copying Menu Objects Between Forms

One problem that occurs frequently is taking the menu structure from one form and placing it in another. Although my method of dealing with this dilemma requires a little effort,

ODBC Error Display

I have seen many posters in the VB newsgroups that say they have received an ODBC error message such as 3146, but can’t figure out why they got the message.

Set Cursor to Control by Default

Sometimes it is useful to set a cursor to determine control when a form is loading-after the form is done loading, the cursor stays on the control you have ordered:

A Better Substitute for GetModuleUsage

To synchronously shell an application from a 16-bit VB application, some people write code like this: Const HINSTANCE_ERROR% = 32Dim hInstChild As Integer’Shell program, if Shell worked, enter loophInstChild =

Entering Scientific Formulas

I have developed this technique to use when I program long formulas. First, I declare descriptive variables for the mathematical elements. I prototype the formula using the digit “1” as

Create Queries On the Fly

Use VB’s string-concatentation operator (&) to incorporate user input into SQL queries at run time. Assume, for example, that cboField is a combo box containing a list of fields in

Speed Tips

Reading data into and out of a VB program is straightforward. Most folks use the Input and Put statements in a For…Next loop. However, this straightforward technique takes time. Because

Use an ICO File as a Mouse Pointer

If you want to use an ICO file as a mouse pointer, set the MousePointer property to 99-Custom. Then load the icon into the MouseIcon property: Text1.MouseIcon= LoadPicture(“c:vbiconselements_ earth.ico”) For

Data Access Speed

When you connect to remote servers, always use tables attached to theserver through Access. This will significantly speed up your retrievaltime. Once a table is attached to a remote server,

Avoid Using Variants

Variants take more memory and it’s slower to get/set their values thanother data types. Option 1 will run slower than Option 2. Option 1: Dim iLoop As Variant For iLoop

Use the VB Knowledge Base

Get the Visual Basic Knowledge Base from Microsoft. It contains hundredsof ideas (with code samples). I use it daily to get my job done (and findout new things to try

Hiding MDI Children

MDI children can be hidden! Although VB doesn’t directly supportthis, you can use the ShowWindow API call to do so. A simple call likethis will do it: Declare Function ShowWindow

Make MDI Children Invisible on Loading

Contrary to popular belief, an MDI child does not need to be immediatelyvisible at load time. If the Visible property is set to False at designtime, the child will not

Never Have an Untrapped Error in VB

To prevent untrapped errors in VB, put an error handler in the codefor every control/form’s events. Unless you want more granularity, youwon’t need to trap errors in function or module

Load VBX/OCX/DLLs in the Windows System Directory

It’s best to load all shared (or public) VBXs, DLLs, and OCXs in theWindows system directory. Doing so prevents component conflicts betweenshared components that are loaded in the wrong places.

Quickly Evaluate an Expression or Variable

Here’s how to quickly evaluate an expression or variable: While indebug mode, use the Add Instant Watch dialog to quickly see the currentvalue of an expression in your code. Highlight

Find Lost Controls

If a control gets lost on your form, you can select it by choosingits name from the drop-down list at the top of the properties window. Setits Left and Top

Speed Up List Box Updates

When adding a large number of items to a list box, you can greatlyspeed up the process by disabling redraws of it. A quick call to SendMessagedoes the trick. Sandwich

Use the Right Tool for the Job

If you’re running into a roadblock in a particular section of yourprogram, step back and take another look at what you’re doing. There’sa good chance you’re using the wrong tool

Drawing Directly on the Form Saves Resources

You can drop labels and frames out of your application (and their accompanyingresource and memory usage) by writing a small routine to use Print andLine that draws directly onto your

Make a Gauge with MicroHelp’s Controls

You can make a beautiful gauge by combining two MicroHelp controls.Place a Mh3d control onto your form and set the inner bevel just insideof the outer bevel. Place a Mh3dCommand

Validating Text Entries When a DataCombo Loses Focus

When setting focus to another control, the DataCombo in Sheridan’sData Widgets can be forced to validate the text portion against its listby referencing the DataCombo’s IsItemInList property as follows: If

Use the Shortest Variables

Use the shortest data type you can for variables. If you’re going tobe counting in a loop from 1 to 10, for instance, use an Integer not aDouble.

Using the MH3D Calendar Control for Date Math

One of the great unsung heroes in MicroHelp’s VBTools is the Mh3dCalendarcontrol. Place a hidden calendar control on one of your main forms. Withthe .Day, .Month, .Year, and .DateFormat properties,

Using LostFocus Events with Command Button Properties

If you’re using LostFocus events but would also like to set the Defaultor Cancel properties for command buttons, you’ll run into a confusing situation.Those properties trigger the Click event when

Sorting Data Within a Datagrid

Data is sorted by using the “ORDER BY” clause in a SQL statementand then assigning the SQL statement to the RecordSource property of thedata control that the DataGrid is bound