Visual Basic Tips #39


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

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

Proudly presents:
Visual Basic

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


*1. CREATING A REALISTIC PROGRESS BAR

In most installation routines, you'll see a progress bar that 
supposedly represents the degree to which the installation is 
complete. The funny thing is that the installation progress 
bar always seems to sit on 95 or 98 percent forever. If you're 
building one of these for your application, I'd suggest looking
at your process realistically to determine approximately how 
long it's going to take to do each task. If you're creating a 
database, for instance, each table creation will take 
approximately the same amount of time. If you have ten tables, 
each time you complete a table, you could increment your 
progress bar by 10 percent. If you have additional tasks, time 
how long they take and adjust your timing appropriately. I'd 
also suggest running the timing on multiple machines so that 
you get as accurate a timing as possible.


*2. PROVIDING INSTANT FEEDBACK

One of the best things you can do for your users is provide lots of 
feedback about tasks during the run of the application. For instance, 
one simple thing you can do is change the cursor to an hourglass when 
the application is busy doing something. You can do this with a single 
line of code: 

Screen.MousePointer = vbHourglass 

Make sure you switch the pointer back if you display an error message 
or otherwise interrupt the procedure. (If not, the cursor won't click 
properly.) Here's the code to reset the pointer: 

Screen.MousePointer = vbDefault


*3. CONVERTING A .DAT FILE                    
           
A user sent me a question about how to convert a .DAT file into 
something he could use in Visual Basic. The problem is that a 
.DAT file isn't a particular format, as far as I know. The 
solution to the problem would be to get the file format (if 
possible) and use that to interpret the file. Alternatively, 
if the file is in a database format, you might be able to find 
an ODBC driver or OLE DB provider for it.


*4. CREATING A REGISTRATION CODE

There are lots of shareware packages that allow you to register 
electronically, and this is one feature customers really 
appreciate. The key (so to speak) to online registration is the 
ability to generate a key based on a static piece of 
information. For instance, WinZip asks for your name and your 
key. That indicates to me that they are generating the key 
based, at least partially, on the name. For instance, the 
application might add up the character values and multiply them 
by some value. To force the length to a particular size, you can 
Mod the value or simply use the first x number of characters. 
The key is to make the calculation repeatable and reliable. 


*5. JOIN THE VB DESIGN TEAM

Want to help build a real Visual Basic application on the Web? 
Visit the VB Design Team site to read about this interesting 
project--and to find out how to join the project. This is a 
good way to get some experience working on a distributed, 
worldwide team. The team is working on a number of different 
applications that encompass various features not commonly seen 
in VB applications.

VB Design Team 
http://vbdesignteam.com/


*6. Y2K STATEMENTS

While this may seem out of date now, several users have asked 
me recently about Y2K statements from component vendors. Many 
component vendors that have controls dealing with dates put out 
so-called Y2K statements indicating how their components had 
been tested for Y2K compliance. The best source for these 
statements, if relevant, is still the component vendor. As far 
as I know, there isn't a "repository" of these statements 
anywhere online.


*7. ZIP CODE VALIDATION

I'm commonly asked questions dealing with ZIP code validation 
and how to match entered ZIP codes with the city and state 
entry. This is pretty common in many applications and allows 
for more reliable and consistent data entry. However, the 
database of ZIP codes and city/state pairs is not free. The 
best source of information about available vendors is the US 
Postal Service's National Customer Support Center. 

US Postal Service's National Customer Support Center 
http://www.usps.gov/ncsc/


*8. USING ADODB PREFIX IN DECLARATIONS                    
           
A user asked me when she might need to use the ADODB prefix for 
an object declaration. The short answer is that it's not 
necessarily necessary. If you're sure that you have only one 
object named Connection, you don't have to prefix it with ADODB.
In addition, prioritizing libraries in the References window 
will cause one library to be read before another. However, I try
to always specify the library name. This eliminates any possible
confusion or difficulty in understanding which object is 
being used.


*9. VBSCRIPT OUT IN NEXT GENERATION WEB SERVICES

If you've not yet installed Microsoft's Next Generation Web 
Services, you'll be pleasantly surprised to learn that VBScript 
is no longer included or supported. Instead, ASP+ includes the 
Visual Basic 7.0 language, which includes all the new features 
previewed at the Web site listed below. In addition, you'll be 
able to use the new C# (C-Sharp) language within ASP+, as well 
as JavaScript. You can read more about the new technologies here:

Visual Studio Next Generation 
http://msdn.microsoft.com/vstudio/nextgen/default.asp


*10. STORE CONTROL TYPE IN STRING

Many of you are aware of the TypeOf operator, which allows to
you write a statement like this: 

If TypeOf(ctlInput) Is TextBox Then 
   ' do something 
End If 

What you might not know is that you can get the datatype as a
string using the TypeName function. For instance, you could do
something like this: 

Dim strControlType As String 
strControlType = TypeName(ctlInput) 
Select Case strControlType 
   Case "TextBox", "ComboBox" 
      ' do something 
   Case Else 
      ' do something else 
End Select 

Using the TypeOf operator makes this sort of structure tedious to 
build.
