Visual Basic Tips #20


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

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

Proudly presents:
Visual Basic

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


*1. RELEASING MEMORY WHEN YOU QUIT YOUR APPLICATION                 
        
If you're using the End method to close your application, you may be 
unnecessarily tying up resources. That's because the End method 
doesn't remove all forms from memory. To free up that memory, you'll 
need to reboot your system . . . or you can regain those resources by 
unloading each form using the Unload method before you end your
application. To do so, use this procedure:

Public Function UnloadForms()
Dim frm As Form
For Each frm in Forms
Unload frm
Set frm = Nothing
Next frm
End Function


*2. WORKING WITH A MULTILINE TEXT BOX                 
        
Textbox controls don't always contain just one line of text. However, 
you must handle each line separately within your code. The first step 
is to make sure that you've set the control's MultiLine property to 
True. Then, add code that identifies each line as follows: 

Private Sub AddLines(txtBox As TextBox, sFirstLine As String, 
sSecondLine As String) 
txtBox.SelText = sFirstLine & vbCrLf & sSecondLine & vbCrLf 
End Sub  

The vbCrLf code inserts a return (line feed) into the text you're 
sending. That way, Visual Basic stores the text with the appropriate 
line breaks.


*3. CREATING DESIGN-EFFICIENT FORMS                 
        
Your users will spend most of their time entering data on forms and 
clicking buttons, so it's important that you create forms that not 
only pull them through the task, but also reduce eyestrain. A busy 
screen not only confuses users, it slows them down. These 
simple-to-apply guidelines will make your forms easy to view and easy 
to use: 
 
 - Use white space effectively by separating information from the 
surrounding objects using margins and gutters, and by using blank 
lines between subgroups to show relationships. 
- Align fields vertically and set the tab order accordingly. Avoid 
horizontal movement from control to control. 
- Group all your related fields together. Use borders or white space 
to separate these groups from other groups. 
- Left-justify your label text.


*4. JULIAN DATES                 
        
In a previous tip, you learned how to get the "Julian" date for a 
given date using the Format statement. The date we're talking about is 
the day number starting with January 1 of the current year. However, 
several readers have reminded me that this isn't really the Julian 
date. By definition, a Julian date is the number of days that have 
elapsed since noon on January 1 of the year 4713 BC. Thanks to both 
Mike Shaffer and Sid Hollander for this tip.


*5. USING THE JET 4.0 PROVIDER WITH ACCESS 97                 
        
The Jet 4.0 OLE DB provider is able to read Access 97 and Access 2000 
databases. However, a number of problems have been reported with this 
method. In certain cases, the driver will stop responding and will on 
occasion cause 100 percent CPU usage on servers. The solution to this 
problem is to upgrade your Access 97 database to Access 2000. 
Microsoft has promised a Knowledge Base article on this problem, but 
none exists as yet. Thanks to Seth Lipkin for this tip. 


*6. USE DATE DATA TYPE FOR DATE/TIME DATA                  
         
One of the nice things about Visual Basic is that it doesn't have any 
internal issues dealing with Y2K issues. In fact, the built-in Date 
data type is able to hold year values from 100 to 9999. However, if 
you don't ask your users for four digit years, you do have a fallback 
position: Currently, Visual Basic will assume a 20 prefix for all 
two-digit years from 0 to 29 (2000 to 2029), and a 19 prefix for all 
other two-digit years (1930 to 1999). You can test this yourself with 
this code: 

Dim i As Integer 
For i = 0 To 99 
   Debug.Print Format(CDate("1/1/" & i), "MM/DD/YYYY") 
Next i 

The key to preventing these problems is to always ask your users for 
four-digit years in all date values. Don't assume your program won't 
exist in a few years--that was what got us into trouble in the first 
place. 
                
 
---By Susan Harkins


*7. DOWNLOADING COMPONENTS                   
          
Cnet, "the computer network," has maintained a large component library 
for a number of years. At one point, it was located at 
www.activex.com; however, the direct link to the site is now 

http://download.cnet.com/downloads/0-10081.html 

This is a great site with a huge sampling of commercial, shareware, 
and free controls for use in Visual Basic.


*8. COMPONENT REGISTRATION SHORTCUT                   
          
Since I build a lot of COM DLLs on my systems, I've created a shortcut 
to register the components on the system. If you double-click a DLL 
file and don't have a default application already registered for it, a 
dialog box will appear asking which application to use to open the 
file. Navigate to your Windows or Windows\System directory and find 
RegSvr32.exe. If you use this application to open your DLL, it has the 
effect of registering the component. This double-click method is 
easier than having to type in the full command line each time.


*9. CREATING A REGISTRATION SCHEME                   
          
Most software that I use frequently starts out as shareware but 
requires registration after a certain number of uses. There are lots 
of fancy ways to do registration, but the easiest doesn't require any 
software at all. A dialog box for registration will typically ask 
people for their name and registration number. What you can do is use 
the person's name to generate the registration number. The only real 
requirement is that you can generate the number again in a reliable 
fashion, which means random numbers can't easily be used. However, 
there are lots of other things you can do. For instance:


*10. RESPONDING TO THE COMMAND LINE                   
          
One of the less-used features in Visual Basic these days is the 
ability to read the command-line arguments. Using command-line 
arguments was almost a necessity in DOS days; however, it can still be 
used today with "Windowed" applications. 

Any arguments you put on the command line are available at runtime 
through the Command$ function. The name of the application isn't 
provided, unlike applications written in languages like C or various 
shell scripting languages. However, anything else you put on the 
command line is put exactly as is into the Command$ function. 

If you're testing, you can go to the Make tab of the Project 
Properties dialog box and enter whatever arguments you want to use for 
testing. These will be put into the Command$ function for you to use 
within the VB environment. 

Once you have the arguments in the Command$ function, you have to deal 
with them. Normally, DOS options use this format: /option value 
/option2 value. There are other variations--use just about any DOS 
command with a /? option and you'll get a dump of the available 
options, either through text output or a message box popup. You can 
then use the Split function to break the string into multiple array 
records based on the location of the slash. You'll need to check to 
make sure the arguments are valid, based on your flag scheme. Just 
make sure you do support the /? option to display the available 
options, since of course, no one ever uses the online help.
