Visual Basic Tips #34


----------------------------------------------

TipWorld - http://www.tipworld.com
The Internet's #1 Source for Computer Tips, News, and Gossip

Proudly presents:
Visual Basic

----------------------------------------------


*1. OFFICE ERROR MESSAGES                 
        
If you use any Microsoft Office objects in your VB applications, 
you might be interested in an Excel workbook that lists all the 
Office error messages and their corresponding values. This file,
Errormsg.xls, is available by download at  

http://www.microsoft.com/office/ork/2000/appndx/toolbox.htm#custalrt 

Once you've downloaded the file--an EXE file, which you should
find in the Program Files\ORKTools\Download\Documents\Cstalert 
folder--run it. The EXE file will install several files, 
including Errormsg.xls. At that point, open Errormsg.xls in 
Excel. Each Office application has its own sheet--simply click 
the corresponding tab to view the error messages for an 
application. Since you're working with an Excel workbook, you 
can easily add your own notes and information to each record.


*2. NEED A CALCULATOR?                 
        
Normally, we like to share expressions and formulas that you can 
use in VB. However, we've found a Web site that may make some of 
your work unnecessary. The Calculators On-Line Center at 

http://www-sci.lib.uci.edu/HSG/RefCalculators.html 

offers more than 5,000 Web calculators. You'll find calculators 
to handle all sorts of tasks, from a lye calculator (for making 
soap) to a capital gains calculator. 

You can easily convert and incorporate these calculators into 
your VB projects using Microsoft Web components.


*3. SPEAKING OF CALCULATIONS                 
        
In our previous tip, we told you about a Web site with 
downloadable calculators for all kinds of tasks. However, most 
of the time, you'll have to rely on your own expressions to get 
the results you need. Occasionally your expressions return 
errors and there are several reasons why VB can't evaluate your 
expression. Here are a couple of quick checkpoints to review 
before you start pulling out your hair: 

- Make sure you've included the right number of parentheses 
  (each opening parenthesis requires a closing parenthesis). 
- Make sure you've supplied all the required arguments for any
  functions or procedures. 
- Check all your object and variable references to make sure
  they're correct.


*4. ADDING MULTIPLE CONTROLS THE EASY WAY                 
        
Generally, you add controls to a userform by clicking the 
appropriate control button on the Toolbox and then clicking 
inside the userform. If  you want to add a second (or several) 
controls of the same type, you probably return to the Toolbox 
and click the same button before inserting the additional 
control in the userform. Fortunately, this repetitive task 
isn't necessary. 

If you want to add several controls of the same type to a form 
or report, simply double-click the control button instead of 
using a single click. Double-clicking a control button 
temporarily selects that control, so you can insert as many 
controls as you like without clicking that button again on the 
Toolbox. To reset the current tool selection, click another 
control button or the Selection arrow on the Toolbox.


*5. UNLOADING FORMS                 
        
You may think you've quit an application, but unless all the 
application's forms are closed, the application will think it's 
still running. If your application has only one form, you can 
add a procedure to the control and event that quits your 
application. For instance, the following procedure uses a 
command button named cmdQuit: 

Private Sub cmdQuit() 
 Unload Me 
End Sub 

If you have multiple forms (more than one), you'll need 
something a little more complicated. The procedure below will 
loop through the Forms collection and unload each form: 

Private Sub Form_Unload (Cancel As Integer) 
Dim I As Integer 
For I = Forms.Count - 1 to 0 Step - 1 
  Unload Forms(i) 
Next 
End Sub 

Attach this procedure to the main form's Unload event. That way, 
when you close it to end your application, the code in the 
unload event will close any forms that remain open.


*6. SPEED THINGS UP BY CHANGING YOUR COMPILE OPTIONS                 
        
If you have the Professional or Enterprise edition of Visual 
Basic, you can speed things up a bit by changing the method of 
compilation to native code. Both versions offer two compilation 
options: Compile to P-Code, Compile to Native Code. 

P-Code (psuedo code) is a go-between for your application and 
your computer's processor. If you're using P-Code, Visual Basic 
translates each p-code statement to native code when you run the 
program. Compiling directly to native code eliminates this 
extra step.


*7. VIEWING MORE THAN YOU THOUGHT                 
        
Do you sometimes wish you had two monitors and two pairs of hands 
when working in the module window? If you need to view different 
parts of your code at the same time, simply split the worksheet 
into two panes. I find a horizontally split module particularly 
useful when I need to return to the beginning of a function to 
add a declaration. I just hop up to the top pane, add the 
declaration, and then hop back down to the bottom window and 
return to my code. This isn't the only use for a split module; 
it just happens to be my favorite. 

If you want a horizontal split, drag down the split box (the 
small rectangle that rests on top of the vertical scroll bar). 
You'll take similar steps to create a vertical split, except 
drag the split box that's to the right of the horizontal scroll 
bar. Once you've split your module into two panes, you can scroll
either pane to find any section of the same module.


*8. DELETING A SPLIT SCREEN                 
        
In our last tip, we showed you how to split a module into two 
scrollable windowpanes. This tip is particularly useful when 
you're working with a large module. To return your view to just 
one pane, simply remove the split. To do so the hard way, drag 
the split bar back to its originating split box. The easiest 
way to eliminate a split module is to simply double-click the 
split bar.


*9. PRINTING HELP TOPICS                 
        
You can easily print Help topics by clicking the Print icon in 
the Help window. However, as you know, most Help topics are 
spread across several pages with many subheadings. That means 
you must access each one and print it to get a set of the 
entire Help topic. Right? Not anymore. To print the entire 
topic, first locate the appropriate book in the Contents tab. 
Next, click the Print button. In the Print Topics dialog box, 
click Print the Selected Heading and All Subtopics. Finally, 
click OK twice. 

Furthermore, VB prints the topic continuously, rather than 
printing each heading on a separate page.


*10. COPYING TOOLBAR BUTTONS                 
        
It's fairly easy to copy a button to a toolbar using the 
Customize dialog box. Simply right-click a toolbar, select 
Customize, click the Commands tab, find the appropriate category,
and then locate the button you're looking for in the Commands 
control. If, however, the button is already on a toolbar, there's
an easier way. Simply open both toolbars--the one that already 
has the button and the one you want to copy the button to. Then, 
hold down the Alt button and drag the button from one toolbar to 
another. It really is that easy!
