Showing posts with label Visual Basic. Show all posts
Showing posts with label Visual Basic. Show all posts

Thursday, December 18, 2008

Fan Mail Letter of the Week--December 18, 2008

I received this email today... it's a nice example as to why I love to write books that help people.

Hi John,

Yesterday I bought your pdf version of LTP with VB.net.


I would also like to use an opportunity to thank you for everything I have learnt through your books.

I know you have heard this "zillion" times, but still...

I own all of your VB6 books which were the starting point of my learning. They gave me very, very good basis for my subsequent learning. I doubt I would be where I am today without your books.

Your teaching style is second to none, by far...

And your ability to "step into beginners shoes" is unbelievable. I don't believe you can learn this...you're blessed with a very rare talent...but you already know that ;-).

Keep up the excellent work!

Take care and I wish you and your family all the best in 2009 (and beyond).

Greetings from Slovenia,
Samo

Monday, April 23, 2001

Developer Career Tip #0041---Update on VB.Net

Developer Career Tips #0041

Update on VB.Net

As I mentioned in my last article, I'm seeing more and more attention focused on VB.Net. Conferences are teaching courses on it--despite the fact that Beta1 of the product is just a few months old, and Beta2 isn't due out until May. Several books have been published on the Beta itself (I've been tempted and ASKED to write one myself). Personally, I just don't get it.

I understand the need to be 'up' on a product more than most people---I make my living as a consultant and author, and the need to stay current is crucial---but I can't ever recall this much pre-hype over a software development product.

I receive at least ten emails each week from readers asking me if they should begin learning VB.Net right now (presumably from the Beta), how much worth I think the VB6 Certification exam will carry (I can't even guess), and whether there will be Learning Edition, Professional and Enterprise editions of the product.

And now the picture is even more complicated. It's no secret that Microsoft intends to 'retrofit' Beta2 of VB.NET to be more compatible with Visual Basic 6. As far as I'm concerned, the waters are now more muddied than ever.

The bottom line is to stay the course: if your goal this year was to learn Visual Basic 6, or become certified in the product, then that's exactly what you should do. Timelines indicate that VB.Net--when it appears---will probably be available in early 2002. You'll have plenty of time to learn it at that point--hopefully with books and courses that are at least based on Beta2.

Monday, March 12, 2001

Developer Career Tip #0040---Should you turn your attention to VB.Net?

Developer Career Tips #0040

Should you turn your attention to VB.Net?

I'm seeing quite a bit of attention to VB.Net recently. More than one book has already been published on it already, plus I've received several email solicitations to attend classes on VB.NET, and the product hasn't even been released yet--in fact, it's in Beta1. Beta2 is schedule for release sometime this quarter. If all goes well for Microsoft, the production version will be ready before the end of the year. This is an awful lot of hype for a new version.

I've been using Beta1 now for the last four months as I write the update of my Visual Basic 6 book for VB.Net. I signed a non-disclosure statement to work with the Beta, so I can't speak about the details of the language, but I can tell you that in my opinion, it's much too early to start working with it, but let me give you some information which may help you make up your own mind.

First, don’t consider VB.Net a new version of Visual Basic. Although a knowledge of previous versions of Visual Basic will serve you well while learning it, there are enough dissimilarities to make you believe you are dealing with a new language altogether. This may well be a reason to be the first kid on the block to know the language---that knowledge could make you very valuable to employers--provided they adopt the language.

Secondly, if you believe that it's a foregone conclusion that you're going to be forced to learn VB.Net, and you may as well learn it sooner than later, you may want to rethink that position. In the latest edition of the Visual Basic Programmer's Journal, the editor indicates that Microsoft has informed him they intend to 'support' both VB6 and VB.Net. The key question---what does 'support' mean.

The bottom line is that at this point there's no rush to learn VB.Net.

Monday, July 31, 2000

Programming Tips & Tricks #0008---Visual Basic Command Line Arguments

Programming Tips & Tricks #0008

Visual Basic Command Line Arguments

I recently received an email from a reader who wanted to know if its possible to run a Visual Basic executable program with command line arguments. The answer is yes, although this feature is not as robust as it is with executables compiled with other languages such as C.

What's a command line argument, you might ask?

Let me give you an example. Suppose you want to execute a program whose main form obtains its caption from an argument supplied by the user when the program is executed.

You can take advantage of Visual Basic's Command function, which returns a value equal to the argument supplied after the name of the Visual Basic executable. For instance, if the name of your executable is Test.exe, if you type this value into the Windows Start-Run dialog

Test.exe VB

and enter this code into the Load Event Procedure of the Startup Form

Private Sub Form_Load()

If Command <> "" Then
Form1.Caption = Command
End If

End Sub

when your form appears, "VB" will appear in the form's caption. Notice that we first check to see if the return value of the Command function is equal to an empty string, which will be the case if the user executes your program with no arguments.

Invariably, the next question that is asked is whether you can supply more than one argument to the executable. Other languages, such as C, populate multiple command line arguments separated by spaces into an argument array that is available to the program when it executes.

In Visual Basic, however, everything that appears after the name of the executable is considered a single string argument. Separating multiple arguments with commas, quotation marks, or other delimiters won't affect that--everything after the executable name is considered a single string argument and is returned as a single string from the Command Function.

For instance, typing this statement into the Start-Run Dialog Box

Test.exe I,love,VB

results in the form's caption being set to "I,love,VB".

However, with a little imagination and some string manipulation, it isn't difficult to come up with a workaround to this restriction.

Developer Career Tip #0008---How to get that elusive first programming job with no experience

Developer Career Tips #0008

How to get that elusive first programming job with no experience

I'm forever being asked by my Visual Basic students how to obtain a Visual Basic programming position in today's job market, when you have no 'paid' Visual Basic experience.

I still insist that there are three sure-fire ways to obtain a Visual Basic programming position (at least a junior level position).

The first is to write a fantastic application based on something you know, and showcase that program at your interview. I had a student in a class a few semesters ago who showed me a Visual Basic program he wrote to keep track of the golf handicaps in his weekend golf league. The program was fabulous, and not only did he land a job with it, he's made quite a bit of money marketing it to other golf leagues in our area.

A second way is to volunteer your programming services---choose a charitable or non-profit organization who may be interested in your free services in exchange for the experience it can bring. Several of my students have written programs for their churches---another wrote a program for a local soup kitchen. You'd be amazed at how demanding a 'real' client can be, even one who ultimately isn't paying cash for the product. But the experience is unbeatable--and it's perfectly legitimate to include a non-paid job like this on your resume---even better if the customer is well pleased and will provide a great reference to a prospective employer.

The final way is to take and pass one of the Microsoft Visual Basic Certification exams---start with the VB6 Desktop Exam. Those of you who have been following my tips know that I'm a big believer in using the exams as a way to get your foot in the door. Hiring managers continue to tell me that passing the exam is a great way to get noticed and interviewed---even if you have no experience.

Monday, July 24, 2000

Programming Tips & Tricks #0007---Global Keyboard Handler in Visual Basic

Tips & Tricks #0007

Global Keyboard Handler in Visual Basic

One of the questions that I am frequently asked is how to implement Keystroke validation in a Visual Basic Textbox. The answer is that you can insert code into the KeyPress Event Procedure of a Textbox--and implement Keystroke validation that way. For instance, this code will ensure that only numbers are entered into a Textbox---it also permits the user to press enter a BackSpace key in case they make a mistake.

Private Sub Text1_KeyPress(KeyAscii As Integer)

If KeyAscii = 8 Then Exit Sub '8 is Backspace

If KeyAscii <> 57 Then 'Range of numeric values
KeyAscii = 0
End If

End Sub

Entering code into the KeyPress Event Procedure of a Textbox is fine for one or two Textboxes---but If you have a large number of Textboxes on your form, this is not an enviable task. In that case, you have two alternatives:

First, you can make each Textbox a member of a Textbox Control Array, in which case each Textbox 'shares' the same KeyPress Event Procedure. Sharing code like that is the chief benefit of a Control Array.

The second alternative is to set up a Form Level or Global Keyboard Handler by telling Visual Basic that you want the Form's KeyPress Event Procedure to be triggered BEFORE the individual Textbox KeyPress Event Procedures.

You do this by setting the KeyPreview Property of the Form to True. This will cause the KeyPress Event Procedure of the Form to be triggered whenever a keystroke is made for any of the Textboxes on the form. What that means is that you can take the code you write for each Textbox KeyPress Event on your form--and place it in just one place---the KeyPress Event Procedure of the Form.

Monday, July 10, 2000

Programming Tips & Tricks #0006---Named Visual Basic Arguments

Tips & Tricks #0006

Named Visual Basic Arguments

One of the themes I emphasize in my computer classes over and over again is the importance of writing code that is readable---that is, code that other programmers and developers will be able to understand, and if necessary, easily modify in the future. Some obvious ways to write readable code include the use of program comments in your code---no matter what the language you are using to develop your program, all major languages provide for comments. Something else that can make your Visual Basic more readable is the user of Named Arguments.

Let me illustrate by executing the Visual Basic MsgBox Function to display a Windows Message Box. The Visual Basic MsgBox function has one required argument (Prompt), and four optional arguments (Buttons, Title, HelpFile and Context).

MsgBox “I love Visual Basic”

By default, this code will display a Message Box with a single command button captioned OK, with the text “I love Visual Basic”, and the Visual Basic Project name displayed in the Title Bar of the Message Box.

Suppose I’m not happy with the default Title in the Message Box, and I decide I want to customize it. Doing this is easy—all I need to do is supply the Title argument to the MsgBox function. However, since Title is the third argument, I either need to supply the second argument---Buttons, which is by default presumed to be the value vbOKOnly---or provide a ‘comma placeholder’, like this.

MsgBox “I love Visual Basic”,, “SearchVB.Com”

Notice the two commas back-to-back, with no value in-between. This is the ‘comma placeholder’ and is how we tell VB that although we have a value for the third argument, we have no explicit value for the second argument.

When we execute this code, we’ll see a Message Box that reads “I love Visual Basic”, and that has “SearchVB.Com” for its Title Bar.

Named Arguments can make passing optional arguments easier—and make your code infinitely easier to read and modify. For instance, the code we wrote above can be re-written to this using Named Arguments.

MsgBox Prompt:="I love Visual Basic", Title:="SearchVB.Com"

With Named Arguments, we specify the name of the argument, followed by a colon and equals sign (:=), then the value for the argument. By using Named Arguments, we don’t need to provide a ‘comma placeholder’ for the second argument Buttons. Since we are naming the argument, VB knows that ‘SearchVB.Com’ is the value for the Optional Argument ‘Title’. And since we name the arguments, being able to read and understand the code in the future is much easier.

Monday, June 26, 2000

Programming Tips & Tricks #0005---With...EndWith in VB

Tips & Tricks #0005

In my consulting practice, I frequently see examples of Visual Basic code that could be improved upon, either from a readability point of view or from an efficiency point of view. Today I'd like to discuss a relatively new Visual Basic construct that can improve both the readability and efficiency of your code---and save you quite a few keystrokes in the process. That construct is the With…End With statement.

The With…End With statement allows you to 'bundle' Property and Method calls to a single object within the With…End With block. For instance, here's some code that sets the properties of a Command Button, and then executes its Move Method.

Private Sub Form_Load()
Command1.Caption = "OK"
Command1.Visible = True
Command1.Top = 200
Command1.Left = 5000
Command1.Enabled = True
Command1.Move 1000,1000
End Sub

By using the With…End With statement, we can eliminate quite a few programmer keystrokes, and make the code a bit more readable in the process---like this…

Private Sub Form_Load()
With Command1
.Caption = "OK"
.Visible = True
.Top = 200
.Left = 5000
.Enabled = True
.Move 1000,1000
End With
End Sub

Not only have we reduced the number of keystrokes in the procedure, but using the With…End With construct produces more efficient code.

Each reference to an object's property or method requires a Registry 'look up' to execute the code statement---by using the With…End With statement, VB is able to 'pool' this lookup into a single Input Output operation---thereby making your program run faster.

The bottom line---whenever you find yourself coding multiple operations against an Object, use the With…End With statement.

Monday, June 19, 2000

Developer Career Tip #0005---Learning Visual Basic---Part 3

Developer Career Tip #0005

Learning Visual Basic---Part 3

In my last two articles, I dealt with ways to learn a new programming language, including taking official Microsoft Curriculum courses at a Microsoft Certified Technical Education Center (CTEC), long term training at a computer programming school or institute, or enrolling in a course at a local colleges or university. All of these options have one thing in common: you need to be present at a predetermined time and place for a specific duration in a classroom led by an instructor. In today's article, I want to discuss an interesting alternative to classroom based training---web based learning.

I've taught programming for 20 years, and up until three years ago, all of it had been via the traditional route of instructor led classroom training. When I was initially approached to teach a web based programming course in Visual Basic (I teach for SmartPlanet and ElementK), I must confess I had my doubts, but within two weeks of beginning the course, I was amazed that not only could web based learning be just as good as traditional classroom based training, but in many ways it was far superior.

From a student's perspective, web based training can solve a myriad of logistical problems. Most web based training is message board based---which means that there's no formal meeting time. Students log in, obtain the week's assignment (usually a reading assignment), and then use the message board to ask questions, and check back later for answers.

For students whose work or personal commitments prevent them from traveling to formal classroom training, web based training permits them to sign into the 'classroom' whenever their schedules permit. Also, many web based programs are self paced, which means you can speed up or slow down the pace of your learning as your schedule demands. And for some students, perhaps the greatest benefit of web based training is that it's typically a fraction of the cost of formal classroom training.

From an instructor's point of view, I was amazed how web based training solved some of the problems I see in my traditional classes. For instance, since there is no formal lecture mode via the Internet, a higher percentage of students actually read the assigned material, since they can't rely on picking up the material in a lecture period. Secondly, since questions and answers are posted publicly on the message board, just about everybody in the class obtains the benefit of the questions that are posed and the answers that I give. Unfortunately, in a traditional classroom setting, students do not always pay attention to the questions others pose, nor listen to the answers.

Monday, June 12, 2000

Programming Tips & Tricks #0004---Printing the contents of your VB project

Tips & Tricks #0004

I recently received an email from a reader who wanted to print the contents of his Visual Basic project to a file.

For those of you not familiar with this Print feature of Visual Basic, you can print an image of any or all of the forms in your Visual Basic project, plus the code in those forms, to a printer for documentation purposes.

In addition to printing directly to a printer, you can also route the print to a text file---either for archive purposes or for subsequent printing.

The problem is that when my reader tried to view the output file using his Notepad Editor, he reported seeing strange characters at the top of the document, and when he printed the file from within Notepad, the results were far from satisfactory.

What causes this is that when he directed the print output to a file, his Windows default printer was set to a high tech model (either a laser or an ink jet printer). The strange characters included in the document were printer control characters that Windows inserted into the file---the same characters that Windows would have sent to the default printer to ensure that the document printed properly..

Fortunately, the fix is easy.

To produce a file that can then be opened cleanly in an editor such as Notepad, you must first install a Generic-Text Only Printer driver on your system (You can do this by Adding a Generic-Text Only Printer via the Windows Print Manager), and then selecting this Printer as the target printer in the VB Printer Dialog Box.

The result is that your output file will contain only text---no special Printer Control Characters.

Monday, June 5, 2000

Developer Career Tip #0004---Learning Visual Basic---Part 2

Developer Career Tips #0004

Learning Visual Basic---Part 2

This is a continuation of my previous article, in which I answered the question, how to learn a new programming language. In that article, I stated that the answer to that question depends on many factors: Do you already know a programming language? How much time do you have to learn one? How do you learn best?

Last time, I described CTEC's (Certified Technical Education Centers), and pointed out these may not be everyone--in fact, they may be a good choice if you already know the programming language you are there to learn!

Are there other alternatives?

Yes, there are plenty.

For instance, there are computer schools that, with programs of varying lengths, turn out graduates that are employable to some degree or other. In my area, schools such as the Computer Learning Center and the Chubb Institute have programs that range from 3 months to a year and teach a variety of programming languages and PC skills. The advantage of a program like this is that you are spending a lot of quality time learning the language. When you are finished, you know it well. The disadvantages are time and cost. You might spend 3 full months, 8 hours or so per day, 5 days per week, learning the language. If you are already employed, this is not a viable alternative, although most of these schools do offer evening hours. Another disadvantage is cost---these schools are not cheap.

A quicker, cheaper alternative are the Professional Development or Certificate programs that many College and Universities are now offering. I teach in such a program myself, and I think they're ideal. For instance, my Visual Basic course meets one time per week, 3 hours per session, for 10 weeks. The amount of classroom time is just about the same as a CTEC, but spaced out more. This permits the students to learn more on their own, spending time in between meetings reading the textbook (and it's an excellent one), doing exercises, and working on a class project.

This one time per week session is less encompassing than a Computer School--but it's also cheaper, and is a good choice for those already employed.

Next time---Online learning alternatives

Monday, May 29, 2000

Programming Tips & Tricks #0003---Changing Control names in VB6

Tips & Tricks #0003

Have you ever wished you had named a Visual Basic control by another name—or come across a project where the original programmer accepted all of the default control names—such as Command1, List1, Text1, etc.

Changing the name of a control is easy---you just need to open up the Properties Window for that control and change the Name property. However, what happens to the code associated with that control won’t make you happy!

The code seems to disappear---in actuality, any event procedure associated with the originally named control is relegated to the General Declarations Section of the form. As a result, when you run your program, that code is never executed.

So how do you “get the code back”?

The code hasn’t really gone away---all you need to do is find the event procedure in the General Declarations Section of the form—and then change the “control name” portion of the Procedure header to the new name of the control.

For instance, if you had this code in the Click Event procedure of a Command Button named Command1…

Private Sub Command1_Click()

Msgbox “I love VB”

End Sub

and then renamed the control to cmdOK---VB ‘moves’ this code to the General Declarations Section of the Form.

All you need to do is modify the procedure so that it looks like this…

Private Sub cmdOK_Click()

Msgbox “I love VB”

End Sub

Now, VB will once again associate this code with the command button---and when you run your program, the code will execute---just like before.

By the way, some of my fellow programmers rename their event procedures prior to changing the name of the control. Either way, the effect is still the same---the code will be associated with the newly named control.

Monday, May 22, 2000

Developer Career Tip #0003---Learning Visual Basic---Part 1

Developer Career Tip #0003

Learning Visual Basic---Part 1

I'm often asked my opinion as to the best way to learn a new programming language.

The answer to that question depends on many factors: Do you already know a programming language? How much time do you have to learn one? How do you learn best?

Are you one of those people who learn best in an instructor-led classroom environment? Can you read a good book or books on a programming language and learn that way? Can you benefit from an online learning experience, where you can take advantage of an instructor or mentor who can answer questions if and when you have them?

In this article, I'm going to examine the classroom environment, and in future weeks I'll be discussing self learning and online learning.

As far as classroom instruction, one alternative is to take a Visual Basic course at a Microsoft Certified Technical Education Center (CTEC).
(For more information on Microsoft Certified Training, check out this web site: http://www.microsoft.com/train_cert/)

There are two main advantages to taking a course at a CTEC.

First, you are assured of taking a course developed by Microsoft and part of the Microsoft Official Curriculum (MOC). MOC courses can only be taught by a Microsoft Certified Trainer (MCT), who must be certified in the subject matter he or she is teaching, and must demonstrate the instructional skills necessary to deliver the material. Secondly, these courses do a good job of preparing you to take the corresponding Microsoft Certification Exam in that subject.

However, there are also disadvantages to the CTEC alternative..

First, the courses are expensive. For instance, you can expect to pay approximately $2000 for a week long Visual Basic course. Secondly, the courses are geared toward computer professionals---so if you are a raw beginner, the material is likely to be over your head. Finally, the courses themselves are very intense, even for someone who has a programming background. For a Visual Basic course, you can expect to be in the classroom 7 hours per day for a solid week---and that can make learning difficult.

Next time---classroom alternatives to the CTEC..

Monday, May 15, 2000

Programming Tips & Tricks #0002---Enforcing Variable Declaration in your VB program

Tips & Tricks #0002

In a previous article, I mentioned the importance of enforcing Variable Declaration in your Visual Basic program by ensuring that ‘Option Explicit’ is coded in the General Declarations Section of each module in your project.

Most high level programming languages force the developer to explicitly declare a variable before using it. Visual Basic is a notable exception. In fact, by default, VB’s installation leaves the Visual Basic environment in a state where variable declaration is NOT required.

After installing Visual Basic, immediately select Tools-Options and check ON

Require Variable Declaration

Selecting this option causes Visual Basic to insert this statement

Option Explicit

into the General Declarations Section of each module in your project. The result is that an attempt to refer to a variable in code without first declaring it results in a compiler error.

What’s the big deal, you might ask? Is there really a harm in leaving this option checked off? Suppose you use a variable in code that you haven't declared? Visual Basic is a programmer friendly language—won’t VB take care of it?

The answer is yes---VB will take care of it---but the price of a mistake on your part can be huge.

For instance, suppose you assign a value to a variable called sngUnitPrice like this…

sngUnitPrice = 13.48

and then later in your code you attempt to refer to this variable in a calculation, but accidentally refer to it by an incorrect name, for instance sngUnitCost (yes, it can happen!)

sngTotalPrice = sngUnitCost * m_intQuantity

You're expecting the program to come up with a valid price--instead, the result will be zero, since the value of the incorrectly named variable sngUnitCost is zero!

When you tell VB to enforce variable declaration, errors like this are caught at compile time---potentially preventing disastrous results form occurring.

Monday, May 8, 2000

Developer Career Tip #0002---Solidifying your Visual Basic interview—take your code with you

Developer Career Tip #0002

Solidifying your Visual Basic interview—take your code with you

About a year ago, a student of mine (let’s call him “Jim”) was called in to be interviewed for an entry level Visual Basic programming position for a major corporation in the Philadelphia area.

While a programming dynamo in the classroom, Jim had no real-world programming experience—and he told me that as the interview progressed, he felt that prospects for an offer were getting dimmer and dimmer. Although he answered effectively all of the questions the interviewer posed to him, he felt that he was getting nowhere in convincing the interviewer that he was right for the job.

Just as Jim believed the interview was about to wrap up, he was asked him if there was anything else he wanted to say. Jim calmly reached into his shirt pocket, pulled out a diskette containing a copy of the Visual Basic project he had turned into me for his class project, and handed it to the interviewer.

The interviewer popped the diskette into his PC, fired up Visual Basic, and for the next half hour, Jim and the interviewer discussed the project. Jim told me that he presented a ten minute overview of the project, and spent the next 20 minutes or so answering questions about the project. The interviewer seemed impressed with the project, and about a week later, Jim was offered the job.

Now don’t let me give you the wrong impression here—Jim’s project, while excellent, was hardly commercial grade. It was a very good project that earned him an ‘A’ in my class---but it was just that, a very good student project.

What Jim and I are both convinced got him the job was not so much the quality of the project—but the fact that he was able to discuss it, explain it, and critique it intelligently and enthusiastically with the interviewer for a full half hour.

That half hour discussion allowed the interviewer to see beyond Jim’s lack of professional programming experience---and realize that in Jim he had found an intelligent, highly effective communicator who could be an excellent team player---valuable skills in today’s job market.

Friday, April 28, 2000

Programming Tips & Tricks #0001---Working with someone else’s code

Tips & Tricks

Working with someone else’s code

The scenario (all too familiar):
You have a new job, and your first programming assignment is to modify a Visual Basic program that was written by another programmer who has left the company. The program is hard to follow. It has no comments, all of the variables are haphazardly named, and all the forms and controls were left with their default names, such as Form1, Form2, Command1, Option1, etc. You’re overwhelmed.

This is not an unusual feeling. In fact, you can feel the same way about your own code a year or so after writing it. So I emphasize these precautionary measures to ensure easy comprehension by others:

1. Option Explicit is coded in all of your modules (this ensures that Visual Basic enforces that all variables are declared before using them)
2. All variables and controls are named using a formal naming convention (i.e. Hungarian Notation)---this makes modifying the program somewhere down the road much easier
3. Code that is repetitive in nature is consolidated into procedures and called from within the program
4. Every module has comments describing its major functions and features
5. Code that is anything out of the ordinary is also commented

Sounds great, but how do these ‘rules’ help you modify someone else’s code? Unfortunately, I’m suggesting you correct the mistakes of the past.

Of course, before you do this, you need to get your supervisor or project leader to ‘buy into’ that plan. Obviously, if he or she is expecting the program modification to be made in about an hour, so taking a week to clean the code and make the modification won’t make you a hit in the Employee cafeteria.

However, I can almost assure you this won’t be the last time this program is modified. Biting the bullet now and cleaning it up will make things much easier on the next junior programmer who finds himself in the uncomfortable position of modifying this code.

Once you have the go-ahead to proceed, the first thing to do is to ensure that Option Explicit is coded in the General Declarations Section of every module in the program. -- if it’s not, add it manually -- and then run the program. Guess what? The program no longer runs. Why?

Coding Option Explicit will cause VB to mark, as a syntax error, every instance of a variable that hasn’t been declared---potentially lethal errors in a program. At this point, you need to identify the variables that haven’t been declared, and explicitly declare them, with a defined type (i.e. Integer, String, Date). While you’re at it, this wouldn’t be a bad time to rename variables using either Hungarian Naming Convention, or a naming convention in use at your company. Using Visual Basic’s Search and Replace features can make this task a lot easier than it sounds.

With all of the variables properly declared and named properly, now is a good time to name those forms and controls in a meaningful way. Keep in mind that when you change the name of a control, the code associated with it can appear to be ‘lost,’ finding its way into the General Declarations Section. To avoid this, first rename any event procedures associated with the control manually with the new name of the control—then bring up the Properties Window for the control and change its Name property there.

At this point, make sure the program runs okay. You’ll find you now have an understanding of how the program works -- so much so, that you should be able to identify code that can be centralized in a subprocedure or function. Along the way, insert comments in your code explaining what’s going on. Write those custom procedures and place them in either a Form Module or a Standard Module (every Visual Basic program I write has one).

Now, with the Visual Basic program nicely sanitized, it’s time to code that simple modification you’ve been asked to make. Hopefully it will be a piece of cake.