Computer Learning Zone CLZ Access Excel Word Windows

Do you know the difference between education and experience? Education is when you read the fine print; experience is what you get when you don't.

-Pete Seeger
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Home > Courses > Visual Basic > VB 6 > QuickStart < QuickStart
VB QuickStart 1

Welcome to Seminar VB 1. Total running time is 2 hours.


 S  M  L  XL  FS  |  Slo  Reg  Fast  2x  |  Bookmark Buy Now

          Only $19
          Members pay as low as $9.50

Lessons

Resources

Questions?

Please feel free to post your questions or comments below. If you have questions about a specific lesson, please specify the lesson number and the time index in the lesson where the issue occurs. Thank you!

Subscribe for Updates

If you would like to be notified whenever changes are made to this page, new lessons are posted, or comments are made, click on the subscribe button.

 

Start a NEW Conversation
 
Only students may post on this page. Click here for more information on how you can set up an account. If you are a student, please Log On first. Non-students may only post in the Visitor Forum.
 
Subscribe
Subscribe to VB QuickStart 1
Get notifications when this page is updated
 
Intro In this video, we'll get started with a beginner's introduction to Microsoft Visual Basic. We'll talk about Windows program objects, properties, events, and methods, and compare Windows and DOS programming environments. I'll show you how to create a basic VB project, add controls like buttons and text boxes, write simple code, rename objects, and document your code with comments. You'll learn how to join strings from text boxes and build a simple calculator that adds two numbers together using the Val function. This tutorial covers the key first steps for anyone new to Visual Basic.
Transcript You should hear audio content playing at this point and you should see our logo on the screen. If you are having difficulties, please email training at amicron.com.

Hello everyone and good evening. It's about 10 o'clock. We're going to get started with our VB course in just a few minutes.

If you have not yet already logged into the chat room, please be sure to do so now. Also, make sure you go into the outline section and download the outline, at least the book one outline for today. You're not going to print it out to follow along in class. You don't have to, but it will make following along easier sometimes.

I'll be back in about two minutes. We're still waiting for a couple of students to join us, then we'll get started.

Good evening once again and welcome to Visual Basic 101. This is our web seminar for Visual Basic. I see we're still waiting for a couple of people to join us in the chat room. If you haven't had a chance yet to download the outline, you can do so online in the outline section.

Let's see if we can... just one moment while I move some things around my screen here.

All right. Let's begin today by going over some basic key concepts.

Microsoft Visual Basic is a programming system using the Visual Basic language and several tools to assist you in building a Windows program.

Computer programs are generally classified in two categories: packaged off-the-shelf programs and custom programs.

We have the evolution of programming languages. There are low-level programming languages like assembly. These are languages that you don't want to program in if you're a novice. They're very difficult to use.

There are medium-level languages like C and C++ that give you more control over the computer than Visual Basic does.

We have high-level languages like VB and Basic and C++. These are more English-like than the mid or low-level programming languages.

To understand the different parts of a Windows program, we can look at a program like Calculator. You can see that the Calculator application has all of the basic features of a Windows program.

A window has some standard parts. We have a minimize button, a maximize button, a close button, a menu bar, and a title bar across the top here.

Then we have some objects in here. For example, this is called a text box. We have the number zero sitting right now. There are some labels on here, and some command buttons—these guys.

The Windows Calculator program has certain properties associated with it. It has height, width, color, etc. Most objects in the Windows program have properties associated with them.

For example, the C or clear button on the calculator has its own properties. The text color is red. The button itself is so many pixels high by so many pixels wide. So every object has its own properties.

Now, Calculator just sits here waiting for us to do something. If you run a Windows program, generally it just sits there waiting for input; it's waiting for you to do something or something to happen.

Windows programs are designed to respond to events. Most objects in the Windows program can respond to certain events, such as when the user clicks on the button. If I click on that nine, I get a nine there in the window.

In addition to responding to events, objects generally have certain built-in functions they can perform, called methods. A method is a bit of programming code that performs a predefined built-in action.

For example, using VB code, you could shut down the calculator by using its close methods or intrinsic commands.

Sometimes these properties, methods, and events are interrelated. For example, you could trigger the onclose event of a form by using its close method. In other words, you can issue a command to cause one of the methods to run.

We'll learn more about these in a future lesson, but I just want to go over how different Windows programs have objects, and those objects have properties, events, and methods.

Now we have Windows and DOS programming. For those of you who have done any programming in the past and you've done some DOS-based programming, Windows programs are different from the old DOS programs.

With a DOS program, you generally had to deal with command line interface. That's a DOS or command prompt. Programs displayed some information, waited for input, and then processed the input. Like it would say, "Enter your name," and you type in your name, and it would do something.

Windows programs generally respond to events generated by the user. For example, you may have to click on a button that says, "Enter my name," and then it would respond to your event.

Programming in DOS was different. You usually had to build your program using only code. Now, development applications such as VB include graphical form builders. You can basically draw your interface. Someone drew these little buttons on here. Probably made one and copied and pasted it.

But the point is, you don't have to just type everything in code. You can design your applications graphically and we'll see how that works.

Now, a good deal of code, however, must still be written to accomplish many tasks. However, the mundane chores of designing the user interface have pretty much been done for you.

Now let's talk about... let's start up VB here. I have VB running in the background. Let's move that stuff out of the way.

When you first start up VB, you will notice the new project window. Here it is. The new project window will allow you to create a new project file.

A project file basically is a file that contains references to all the different objects in your program. We'll talk about that in a bit. Your project is basically your program.

You can get standard EXE, active EXE, active DLL, controls, and VB wizard management. There's a whole bunch of stuff on here, but until I tell you otherwise, you're almost always going to use standard EXE—standard executable program.

So once I tell you otherwise, you're always going to use standard EXE. So I'm going to click on that and then click on OK.

As you can see here, I get the VB integrated development environment. I'm going to just move things around here a little bit on my screen so you can see where I'm doing a little bit better. There we go.

You'll see the standard components of the VB project. You get the menu bar and toolbars across the top of the screen. Very similar to the Windows programs you've seen before.

The toolbox on the left side of the screen is over here. We get different tools we can use: picture boxes, text boxes, command buttons. We'll work with some of those today.

The Project Explorer is on the right side of the screen—that's here. The Properties window is down here below that, where you can see the properties for the currently selected object.

You may see what's called a Form Layout window in the bottom right corner. You can turn that off if you want to. You can turn these on and off by simply clicking on these little Xs here. That will turn these off.

Over here is where you'll see your form. You start building your programs on forms. I'm going to maximize my form so it takes up more space. I have to rearrange things just a bit on my screen.

There's one problem with doing these seminars: with the live seminars, I'm confined to a very small window on the screen. I have to constantly move things around. With the 5.9 CD courses, for example, they're a lot more professionally packaged. I can pause the video recording, move things around a bit, and then resume it. The students can't tell the difference. But unfortunately, with you watching me live, I have to do it on the fly.

So we have a blank form—form1. Just note the Properties window down here on the bottom. Let me scroll over here. Notice the Properties, where it says Properties - Form1. You're seeing all the properties for this form. What are these properties for this form? Let's take a look at some of them.

We've got the Name. Every object has a Name. We've got a Caption property. The Caption is what goes up on the toolbar up here; it's the caption. It's got a BackColor, a BorderStyle, and you can actually scroll down here and see more stuff. We'll talk about a lot of this as we go on: FillStyle, FillColor, ForeColor, all these different things. These are all different properties for that form.

Now let's get started. Now that we have our project all set and ready to go, the first thing we're going to do, oddly as it may seem, is to give the project a name so it's not just called Project1.

The way that I like to do this is, when you're starting a new project, immediately save the project, even though there's nothing here. Let's go ahead and save what we've got.

So I want to click on File and then Save Project As. I like to think of this as a beginning step. My Save As window is way up here. Let me drag that back in where we can see it.

It says "Save File As:" and a name, down here. So just give a name for the form that you're working with.

First, it wants to save the form. Now, it's also trying to save things in the VB98 folder. I recommend you put your stuff instead in a VB folder somewhere on your hard drive, like under My Documents, which is what I normally do. But for the sake of class, I'm going to leave it here in my VB98 folder. I strongly recommend you save your stuff in a VB folder somewhere.

First, it wants to give our form a name. Let's just call this... This will be our sample. We're going to make a sample first. So let's just call this oursample.frm. All forms end in .frm.

Now it wants a name for our project. The project is a whole number. The project basically just keeps track of all the objects in the program. Again, let's just call this oursample.vbp—Visual Basic Project file. Now we can click on Save. That will save that project and let me save that form.

Now let's add a control to it. A form by itself doesn't really do anything, so we have to add some stuff to our form to make it do something. The best way to make it do something is with a command button.

Let's find the command button tool right there. That's the command button. Click on it, bring your mouse over to the form, and then click and drag as if you're drawing a box. Hold the mouse button down, click and drag, then let it go. Now you'll see a big button there that says Command1.

You've just created your first command button. Once you've made a command button, you can move it, resize it, and drag it around. If you've never done any of this stuff before with Microsoft Word objects, it's real simple. With the button, you simply click on it and drag—that will let you move it. To resize it, just move your mouse over one of the borders, click and drag, and that will let you resize the button.

We can also add a text box. Here's a text box. A text box is a box that you can put some data into, as opposed to a label which just sits there on the form saying something—or we'll do a label in just a minute.

Let's drop a text box on here. Here's a text box. So I click on it. Don't try to click and drag it off the toolbar—just click on it to select the tool, then bring your mouse over to the form, and then click and drag. There's a text box.

Notice over here the properties say TextBox1. If I click on this button, notice it says Command1—command button. We can change the object by clicking it.

If I click on the form background, you can see here that it says Properties for Form1. Everything has its own set of properties.

Now, this stuff is all fine and dandy, but by itself it's not really doing anything. Let's add some code to the command button.

Let's go ahead and double-click on this command button. Double-click on it, and that will open up the code window. This is the VB code. In here you can see it says:

Private Sub Command1_Click

What is that? Well, basically, Private Sub is telling you that you're creating a new subroutine. A subroutine is a collection of programming code that goes together. In VB, we call them "subs" or subroutines.

Private just means that only this form can use it. Other forms and other objects cannot utilize the subroutines on this form. We'll talk more about the interesting private and public in a future lesson.

Let's just put some code in here. Go ahead and hit Enter several times to give yourself a couple of blank lines. I'll use my arrow key and go up. Now I'm going to hit the Tab key on my keyboard to move my cursor in. It's good programming style to indent your code so it's a level underneath the Private Sub. All your code should be indented one tab stop.

Now let's just type in the command:

MsgBox

and then a space. As soon as I hit the space bar, this little window pops up. You can ignore that for now. The little pop-up window is just giving you some syntax. It's telling you, "Here's the stuff that you can put into a message box." For now, ignore it and just follow along.

Now I'm going to type in the quotes:

"Ouch. Don't click me, punk"

and then we're done. We just had the first VB command.

What does MsgBox do? MsgBox is going to put a message on the screen in a little box. When I click on my command button, it's going to pop up a little message: "Hey, don't click it. Ouch. Don't click on me."

Let's save our work—it's always good to get in the habit of saving your work often. Click on the little Save Project button. That'll save our work.

Now I'm going to come over here and click on this little triangle-looking button that says Start—that's how you run your program. I'm going to click on that button, and the program runs. Now my window is off the screen here; hang out one second while I go get it. There it is.

We've got our Form1. Here's our command button. This is a program actually running now. If I click on my Command1 button, I get a little window up here. Let me drag it on the screen again so you can see it. There it is. There's our message box. It says,

"Ouch. Don't touch me, punk."

So, what did we do? We created a command button and we put some code in that command button that says: when this button is clicked on, pop up a message box that says "Ouch. Don't click me, punk," with a little OK on it.

So now my only choice is to click on OK, and then I'm back in my program. If I click on this again, again I get my little message box. There it is.

A little simple program, but again, this gives you the basic idea of what a Visual Basic program can do.

Now I'm all done. The text box doesn't do anything yet, so let's close this—it's going to close the program—and then I'll be back inside of VB.

If you have any questions and you're attending this class during our live session, please feel free to ask your questions in the chat room. I'll do my best to answer them.

So we've written our first actual VB program. As you can see, that was pretty easy.

Now, any old user running this program would not have any clue what Command1 means. If they look at your program, and they see Command1—what does that mean? So maybe we want to give them a little more description with that button.

So let's go back into form view. Now, look over here on the Project Explorer. Next to "View Code" it says "View Object." Let's click on that View Object button. That'll put us back into the form. Here's how you can flip between the object and the code with these two little buttons here—there's the code, there's the object.

Now let's click on the command button. That'll bring up the properties down here for the command button. I'm going to slide over here so you can see it.

Here's the Caption right here. That's what we're looking for—the Caption property. Not the Name property. The Caption property controls what the box actually says. Right now, it's set to Command1.

Let's change the Caption to say something else. How about "Insult Me" or "Click for an insult" or whatever. Now as you can see, the button has changed. The button now says "Insult Me" on it. That's the caption.

If I were to run my program right now, my program would say "Insult Me" on the button. There it is. Let me slide back over here. There we go. If I click on it... Don't click me. That's how you change the Caption property. That lets you change the face of the button itself.

Now, there are other properties in here. We've talked about—let me go back to my new code here—we've talked about the Name property. The Name right now says Command1. That's the name of this object. Every object has its own name.

Now, when you start getting into actually writing VB programs, it's a good idea to give all of your objects a good name. Command1 is not very descriptive. Let's change the name of this button. I'm going to change the name of this button to InsultButton. Do not use spaces—you may not use spaces in an object name.

Now, sometimes if you have taken any of the programming classes, you might also see it done like btnInsult. Some programmers prefer to use what's called Hungarian notation, and you put the object type first, so you get something like btn, stands for button, Insult. Me personally, I don't really care for that, so I'm going to call mine InsultButton. That's how I've always done it—from day one, that's a Rick thing. That's how I like to do it. You can use whatever style you particularly care for.

Now, I've given the button a good name: InsultButton. Let's go ahead and run our program. Again, my program is off the screen. There it is. Now I click on my "Insult Me" button, and nothing's happening. Why is nothing happening?

Well, see, I changed the name of my button, and now it's not working. I broke it. Somehow I broke my button. Let's see if we can figure out why. Let's take a look at the code. Let's see here. Oh, look at that. The code still says

Private Sub Command1_Click

But the button's name is different now. If I go back to my form here, my button is called InsultButton. Let's double-click on this guy. Oh, look at that. It put a new Private Sub down here, so there's a double-click on it. What's happening? Well, if you change the name of an object like a command button, all of the code underneath it now won't work, because the code is looking for Command1_Click and not InsultButton_Click.

That's usually fixed easily, though. All you need to do is come up here, highlight that text, and then cut and paste it or move it right down into here. I'll give myself some blank room. Then I can just delete this empty shell up here—this Private Sub Command1_Click up here—we don't need that anymore. I can just delete it. Goodbye.

Now we're left just with the Private Sub InsultButton_Click.

That's one of the questions I get asked all the time: "Oh, I renamed the button and it broke. Now my code doesn't work." Well, that's how you fix it.

Now we're off to a good start. Now we know how to change the properties for our objects.

Let's go ahead and turn our attention to that text box that we created earlier—the little text box right here. Text boxes don't have a Caption property. If you click on it, you won't see a Caption property. Instead, text boxes have a Text property. Let's see if we can find it—scroll down, and there it is.

There's the Text property. Right now it says Text1. If you want your text box to start off blank, instead of saying "Text1," just delete this text right here. Just highlight it and hit Delete or backspace over it. Now your text box will start off blank, which is generally how you want text boxes to start off.

Like our friend the command button, we should also give this text box a meaningful name. Let's click on the text box and find the Name property—there it is. I'm going to change the name. Let's call this MessageText. That's the name of that text box now.

If I want to refer to it using the code, then I will refer to MessageText—again, no spaces.

Now, instead of making the Insult Me button pop up a message box, let's go back here in our code. I double-click on the command button. Let's say instead of MsgBox saying "Ouch. Don't click me, punk," let's put that in the MessageText box that we just made.

So, I'm going to delete the MsgBox command, and I want to type in here:

MessageText = "Ouch. Don't click me, punk"

Notice how I typed "MessageText" in all lowercase. Look at the next line—it corrected the capitalization for me. It set it to "MessageText" with a capital M and capital T. Well, VB is not case-sensitive, but if you do your objects with proper casing (for example, capitalizing the first letter of each word, like "MessageText" or "InsultButton"), then it will capitalize them for you later on in your code when you're typing them in.

That's good because you can check and see if you misspelled something quite easily. Because if I had typed this in a minute ago as just "message text," if I spelled message wrong, as soon as I hit down arrow, just looking at it, I could see how it didn't capitalize "MessageText," so I must have goofed up the spelling and I can fix that.

There we go: "MessageText."

So now I've got it so that it's going to set that text box equal to "Ouch. Don't click me, punk," instead of running a message box.

Let's save our project—always get in the habit of saving often—and let's start the program. There's my Insult Me box. Let's click on it now. And there we go: "Ouch. Don't click me, punk" went right in that message box.

If you're following along with the book, that will put us on page 16—that's book one.

One thing that I would like to teach you early on is the importance of properly documenting your code. First-time programmers often ask why it's necessary to teach documentation, because usually you only have to worry about documenting big programs and stuff that you work on with teams of people.

But documenting your code can come in quite handy, even for small projects. Me personally, I have written some VB programs two, three, or four years ago, and I want to make a small change. So I open up the project, and I look through it, and I'm trying to figure out "What did I do? What does all this mean?" Now, I can't understand my own stuff three or four years later.

Having some comments in your code to explain what you're doing to someone else or to yourself in the future is always very handy. You can insert comments in your code very easily.

I'm going to come right above the "MessageText" line here. I'm going to press Enter to give myself a blank line and tab in. You can create comments just by using the single quote character:

' I'm going to have the computer insult me

Then I'll just use the down arrow or hit Enter.

Notice that the comments are changed to green. That's how you insert comments in your code. That's good because if you have weird formulas that you're doing or strange functions you're going to create (and we'll be creating some), it makes it much easier to follow it in the future—or if you are working on a team with more than one person.

So that's how you do comments.

Again, if you are attending during the live session and you have any questions, you can drop them in the chat room.

Next, we're going to create a new project and we're going to learn about something called string concatenation, where we can take two bits of text and put them together. This is one of the things that people always want to see how to do.

Let's go ahead and close this project down. I'm going to come up here in the upper right-hand corner and close the project by clicking on that X right there. There we go.

Let's click on File and then New Project, and then we're going to go ahead and close the project. Oops, hang on one second, folks; my windows are all moved around here. Actually, now what if I can't get this stuff—I'm going to exit out of VB. If it asks you if you want to save changes to your file, go ahead and say Yes.

Then we'll go ahead and open up VB again and we'll create a standard EXE. So, our next project: standard EXE.

I'm going to turn all my side windows off. In case you accidentally do that—I accidentally turned off my project and properties forms—let me do that again. I'll just show this to you: I turned them off, and then they go, that's trying to get stuff. But if you come right up here and click on View, you'll see them down here: View Project Explorer (there it is) and View Properties Window (there's that one). Then you're back at those.

So, new project. I'm going to maximize my form. I'll resize these a little bit.

I want to create three text boxes and a command button on here. I'll put the first name in, the last name in—like Joe Smith—click on the button, and have them put together in the third text box.

Let's go ahead and do it: Textbox number one, click and drag it out. That says "Text1." I'll resize it a bit. I'm going to blank out that text property, scroll down here and find Text, and get rid of that—let's just blank it.

I want to create three of these, so why don't I just copy and paste this? Can we do that? I'm going to right-click it and go to Copy, and right-click out here and go to Paste.

Now, with that, it's going to say, "You already have a control named Text1. Do you want to create a control array?" What's a control array? Don't worry about it—we'll talk about them in a future lesson, time permitting. For today, I'm going to say No. I don't want to control array. That will drop that box right up there. Let's slide it down underneath.

Now, I'm going to paste one more: right-click, Paste, control array—No, and there it is. Let's slide it down here to the bottom.

There we go: now I've got my first name, my last name, and my full name, we'll call it.

Let's give these text boxes some good names. Click on the first one and slide over to my Properties box. For the first one, I'm going to call it FirstName (again, no spaces). You can call it FirstNameTextBox or FirstNameTxt, whatever you want. I just call it FirstName.

I usually name my objects to fit the context of the program. If it's a simple program like this, FirstName is fine. If I had 15 controls on here, including a first name text box and a first name button, then I might get more complicated with the names. But FirstName and LastName are good. The bottom one down here, I'm going to call FullName.

Why am I renaming these boxes? Because I don't want to have to remember, "Okay, this one is Text1, that one's Text2, this one's Text3." I just want to give them good names, then I can refer to those: LastName, FirstName, and FullName.

I will type in the name here, the last name here, hit a button, and then it will land down here.

So, let's grab a command button—drop it right here in the middle. There we go.

Let's give it a good name: let's call it MergeButton. How about that, the MergeButton. We're going to merge the names together. Let's put in here, for the caption, "Merge Names." That will merge the two names together.

Now we're ready to put some code behind the button.

Let's put some code in the button. Let's double-click on "Merge Names." Here we are in our code. I'm going to put in there:

FullName = FirstName & " " & LastName

Let's save it first. Let's call this MyNamesForm. We'll call this the NamesProject.

Now we can run it. When we run it, we get this guy. Let's put some names in here. I will put my name in here: Richard Rost.

I will hit my Merge Name button. It concatenated them together. One thing about programming is that the computer is going to do exactly what you tell it to do—it is not a mind reader. We told it to put together "Richard" and "Rost." We did not say anything about putting a space between them.

We have to adjust our code. Let's put a space in between FirstName and LastName. If I put an X in there, it will put an X in there. If you want to add a space, add a space.

Now I will put a new name in here—let's try "Joe Smith"—click on "Merge Names" and you get "Joe Smith." Now you can join two strings together.

Let's take a moment to change some of the other attributes of our form. Let's go back to our form. Let's click on the form itself and slide over here. I'll drop the button down.

I've never used the system colors. I'll click on the color palette. Let's select that. You can click on any of those colors you want. You can also type in your own numbers.

You can change the back color (background color) for your form. You can also change color for text boxes. You can change the background color of the form.

Let's see here. It doesn't change the background color for the label, it changes something different.

You can also change the font. If you don't know how to change fonts, you can change it here.

Let's run our project and see what we've got. Let's look at the form.

The form itself is called Form1. You can rename that if you want. We're going to be building programs in the future that are going to have multiple forms. Let's call this "Names." You can put spaces in there, because the caption is what goes up on the toolbar.

There are some other properties. You can set the Enabled property to False; it will make this button grayed out so you can't click on it. There's a Tooltip property—hold your mouse over it when you run your project, and it will show the tooltip text.

You can resize the textbox a little smaller and add some labels over to the left. Let's slide back over here. There's no way I can show you right now how to resize a group of these labels, but let's put a label.

Go over here and change the Caption property. Set the Caption. For example: "First Name," "Last Name," and "Full Name."

I'm crazy trying to keep up with going back and forth here, but I have a very small window to work with. I have to sometimes scroll back and forth.

With some programs, like teaching Word or Excel, it's not that bad, but with VB I'm constantly having to go back and forth on the screen from the left to the right, so bear with me.

Now that we have some labels on here, you can see that our program makes a lot more sense. Now, someone that looks at it sees "First Name," "Last Name," and that's what the labels are for.

Now, some people don't know about the little X in the upper right-hand corner—some people have never used it before—so I want to give them a button over here that says Exit Program. Again, real simple, but I just want to get you to build another command button and teach a new command. Let's shrink up this button just a little bit and drop another one on here—a command button, drop it right here.

Let's give it a good name. Let's call it ExitProgram. I'll just type in the caption "Quit," and let's put some code behind the button.

Double-click—now I'm in ExitProgram_Click. There's one little command that will get us out of a program, and that command is just simply:

End

That will exit the program as soon as it's clicked on.

Save it, run the program, let's grab the window, and this time I'll just click on the Quit button and it exits the program. That's all it's supposed to do—a little quit command.

Time for a real program.

These samples we've been using so far are going to teach the basics, but they don't really do anything. Let's make a new project called Simple Calculator. Again, we're going to have three text boxes and a button, and we're basically going to add two numbers together.

In fact, we don't need to create a new project—we could just use this one. Let's save this file: Save Project As. Let's save this as "MySimpleCalculator" for both the form and the project name.

There are two text boxes for input, a text box for output, and a button to sum them up. So, real quick, put in text boxes: text box number one. Come over here, change the Text property to blank, copy it, and paste it.

Control array? No. Let's put that over here. Paste another one, drag that one down below, and it's TextBox3.

Let's give these controls names. The name for the button will be CalculateSumButton.

When I click on it, it will calculate the sum of the two boxes, and for the Caption, I'll just put "Sum."

This guy here—let's call this one Value1. The next one, Value2. And the one on the bottom, Result.

If you missed all that or it's in the outline, don't worry. We have Value1, Value2, the Result, and of course the CalculateSumButton.

Now, my goal is I want to be able to put values in Value1 and Value2, hit the Sum button, add them up, and get a value on the bottom.

How do I do that? We'll need some code.

Double-click on the Sum button. Let's just say:

Result = Value1 + Value2

Makes perfect sense: take the Result and set it equal to Value1 plus Value2. Everything should be good to go.

Let's save our work and run the program. Let's see what we get. Let's type in 10 and 20, and I should be able to hit Sum and get a 30.

Oh, wait—something's wrong! I got 1020. What's going on here? Well, VB is treating those text boxes as text, so it's concatenating the strings—even with a plus, it's treating those as text strings.

So, we have to tell VB, "Don't treat those as text, treat those as numbers and use their values"—the value of the box plus the value of the second box. We can do that using the Val function.

Right in front of Value1, I'm going to type in:

Val(Value1)

The Val function.

So, take Value1 and give me its value. If you've done any work before with Excel, you've used functions like Sum. You'd say in a box:

=Sum(A2:C3)

What does it do? It takes this stuff in the middle, sends it into the Sum function. Think of the Sum function like a little black box: you dump some stuff in, shake it up, and it spits something out.

That's what the function is. Maybe the Average function you've used:

=Average(A2:C3)

This is the Val function, and the Val function is straightforward: take a text string and give me its numerical value.

We'll do the same thing over here with Value2:

Val(Value2)

Take the value of Value1 and add to it the value of Value2.

Now let's save it, run it, and let's see what we have. Let's type in 10 and 20, hit the Sum button, and there we go—there's our 30.

So now, using the Val function, we can add together the value of two text boxes.
Quiz Q1. Which statement best describes Microsoft Visual Basic?
A. It is an operating system for Windows computers.
B. It is a high-level programming language and development system for building Windows applications.
C. It is exclusively used for command-line programming.
D. It is primarily designed for web development only.

Q2. In Visual Basic, what are the three main characteristics associated with an object like a command button?
A. Style, version, and platform
B. Properties, methods, and events
C. Memory, disk space, and speed
D. Buttons, icons, and pointers

Q3. What is the difference between a DOS program and a Windows program according to the lesson?
A. DOS programs use graphical interfaces, Windows programs use command-line interfaces.
B. DOS programs respond to user-generated events, Windows programs only use sequential code.
C. DOS programs require all interface design to be done with code, while Windows programs allow graphical interface design.
D. Both require the same programming techniques and user interfaces.

Q4. What should you do first when starting a new Visual Basic project?
A. Start coding the main functions immediately
B. Save the project and form files, giving them meaningful names
C. Add pictures and icons to your form
D. Set up a database connection

Q5. What happens if you rename an object like a command button in Visual Basic after you've already added code to it?
A. All existing code works automatically with the new name
B. You must retype the entire code from scratch
C. The old event handler will not work, and you need to move your code to the new event handler with the correct name
D. Visual Basic automatically updates all code references

Q6. How do you display a message to the user in a simple pop-up box in Visual Basic?
A. Print "message"
B. ShowMessage("message")
C. MsgBox "message"
D. Toast("message")

Q7. What property should you clear in a TextBox to ensure it starts off blank at runtime?
A. Name property
B. Caption property
C. Value property
D. Text property

Q8. Why is it important to give objects, such as buttons and text boxes, meaningful names?
A. It allows multiple objects to use the same name
B. It makes your code easier to read and maintain
C. Visual Basic requires all names to start with "obj"
D. It increases the program speed

Q9. How do you add documentation or comments to your Visual Basic code?
A. Precede the comment with two forward slashes (//)
B. Place the comment inside curly braces {}
C. Precede the comment with a single quote '
D. Write comments in a separate file

Q10. Which operator is used in Visual Basic to concatenate two strings together?
A. +
B. &
C. #
D. *

Q11. Why did the initial attempt to sum two TextBox values in the calculator program result in string concatenation (such as "1020" instead of "30")?
A. The plus operator only works with numbers in VB
B. TextBoxes always store values as numbers
C. The values were treated as strings, so VB concatenated them as text
D. The TextBoxes were set to the wrong font

Q12. What Visual Basic function can you use to convert a string from a TextBox to a numeric value for calculations?
A. Convert()
B. ToNumber()
C. Val()
D. Num()

Q13. What does setting a button's Enabled property to False do?
A. Changes its color to red
B. Makes the button disappear
C. Disables the button so the user cannot click it
D. Renames the button

Q14. How do you run or start the Visual Basic program you are working on from within the IDE?
A. Select Run from the File menu
B. Click the triangle-shaped Start button in the toolbar
C. Close the Properties window
D. Double-click the form

Q15. What is the main purpose of using labels in a Visual Basic form?
A. To display instructions or descriptions next to controls like text boxes
B. To accept data input from the user
C. To navigate between different forms
D. To execute code when clicked

Q16. If you want a button to close your program when clicked, what simple command should you put in its click event?
A. Stop
B. CloseAll
C. End
D. ExitApp

Q17. Which property of the form determines the text shown in the title bar?
A. Name property
B. Caption property
C. Heading property
D. Label property

Q18. If you want to switch between viewing the object design and code for your form in the Visual Basic IDE, what can you use?
A. The Save Project command
B. The Project Explorer icons for View Object and View Code
C. The File menu
D. The Label caption property

Answers: 1-B; 2-B; 3-C; 4-B; 5-C; 6-C; 7-D; 8-B; 9-C; 10-B; 11-C; 12-C; 13-C; 14-B; 15-A; 16-C; 17-B; 18-B

DISCLAIMER: Quiz questions are AI generated. If you find any that are wrong, don't make sense, or aren't related to the video topic at hand, then please post a comment and let me know. Thanks.
Summary Today's video from Visual Basic Learning Zone introduces the basics of programming in Microsoft Visual Basic. The session begins with some housekeeping for those attending live, such as joining the chat and downloading the class outline. Even if you prefer not to print it, having the outline can make it easier to follow the lesson.

Starting off, I explain Microsoft Visual Basic as a programming environment that uses the Visual Basic language along with a set of tools to help you create Windows applications. Programs in general can either be off-the-shelf or custom-built, and Visual Basic is one of the high-level languages that provide a more English-like approach compared to low-level languages like assembly or mid-level languages such as C or C++.

To illustrate some key concepts, I talk about the structure of a typical Windows program, using the Calculator application as an example. Each window includes familiar elements like minimize, maximize, and close buttons, as well as objects like text boxes, labels, and command buttons. Every object in a Windows program has certain properties—such as dimensions, color, or text—that define its appearance and behavior. For instance, the Calculator's Clear button has unique properties for size and color.

Windows programs do not simply follow linear progression like older DOS programs; instead, they are event-driven. This means the program waits for the user to interact—for example, clicking a button or entering text into a box. Each of these actions triggers an event that the program can respond to. Objects in these programs can also carry out built-in actions, known as methods. Sometimes methods act as a way of triggering events directly from code.

If you have previously programmed for DOS, you will recognize how much has changed. You no longer have to manage everything through code on a command line; instead, development tools like Visual Basic allow you to create your interface graphically, drawing text boxes, buttons, and so forth, then arranging them visually.

Once you start Visual Basic, you see the New Project window, where you can select the type of application to build. For our lessons, you will nearly always use the "Standard EXE" option. Inside the integrated development environment (IDE), you find standard features such as menu bars, toolboxes, the Project Explorer on the right, and the Properties window, all of which help you access and modify different aspects of your project.

Forms are the basic building blocks of a Visual Basic program. When you begin a project, you start with a blank form where you can place controls like buttons and text boxes. Each form and control has a set of properties you can adjust, such as its name, caption, colors, and so on.

It is a best practice to save your projects immediately, even before adding much to them, to ensure you do not lose your work. When you save for the first time, you will provide both a name for your form and for the overall project file. Visual Basic project files have the extension .vbp and forms use .frm.

Next, you add a command button to your form, which you can move and resize just like objects in Word. Adding a text box is similar: select the tool, draw it onto the form, and modify its properties. Every object you add is listed in the Properties window, allowing you to adjust its settings individually.

To make the button do something, you write code attached to its click event. Double-clicking the button brings up the code window. You will see something like "Private Sub Command1_Click," indicating a subroutine that will execute whenever the button is clicked. "Private" means this code is only available to this form. Indenting your code properly underneath the subroutine header is essential for both readability and good programming habits.

To demonstrate your first command, enter the MsgBox instruction to pop up a message when the button is clicked. Running your project allows you to see this in action: clicking the button displays the specified message.

To improve user experience, it is important to give your controls more descriptive names and captions. Instead of "Command1," change the button's caption and name (for example, to "Insult Me" and "InsultButton") so it is clear to the user what its purpose is. If you rename a control, make sure to update your code as well because the subroutine name relies on the control's name to function.

For text boxes, instead of the Caption property, you use the Text property, which specifies what appears in the box. Usually, you want this to start off blank. As with buttons, you should give text boxes meaningful names, making the code easier to follow and maintain later.

Instead of having your button display a message box, you might want it to change the text in your new text box. Updating the code to do this gives you a simple example of how controls can interact with each other in your program. Visual Basic automatically adjusts the casing of control names in the code window, making it easy to spot mistakes.

Another important subject covered is code documentation. Many new programmers are tempted to ignore comments, thinking they are not needed for small projects. However, commenting your code is invaluable since you may not remember your own logic months or years later. Insert comments by using a single quote character, and Visual Basic highlights these in green, making them easy to spot.

With those basics in place, I move on to creating a simple project that concatenates two strings. Using three text boxes (for first name, last name, and full name) and a command button, you can collect input and display a combined result. By appropriately naming your text boxes (such as "FirstName," "LastName," and "FullName"), you make your code self-explanatory. Programming the button to combine the two names in the third text box introduces the concept of string concatenation. Remember to add a space between the names for proper formatting.

You can also experiment with changing various properties of your controls, such as colors, fonts, and captions, to customize the appearance of your application. Adding labels next to your text boxes gives clear visual cues to the user about what information to enter.

For additional functionality, you can add an "Exit Program" button. Give it a meaningful name and set the code behind it to simply close the program with the End command.

To illustrate more practical programming, I walk you through building a simple calculator that adds two values. Again, the interface uses labeled text boxes, and this time, the code needs to treat the contents as numbers. By default, text box contents are seen as text, so adding "10" and "20" would give "1020." To perform arithmetic, use the Val function to convert the text to numbers before the addition. This technique is similar to using functions in Excel, processing input and returning a result.

With these steps, you learn to set up basic controls, write straightforward code, document your work, and manage simple data types in Visual Basic. Each lesson builds on the previous, preparing you for more advanced features in the future.

You can find a complete video tutorial with step-by-step instructions on everything discussed here on my website at the link below. Live long and prosper, my friends.
Topic List Introduction to Visual Basic and its environment
Differences between packaged and custom programs
Evolution of programming languages
Overview of Windows program elements
Understanding objects, properties, methods, and events
Windows programs vs DOS programs
Using the Visual Basic Project Window and project file types
Working with the VB Integrated Development Environment
Explanation of VB toolbox components
Managing VB project windows: Project Explorer, Properties window, Form Layout
Saving a new VB project and forms
Adding and configuring a command button to a form
Resizing and moving controls on a form
Adding and configuring a text box to a form
Accessing and editing properties for forms and controls
Adding code to a command button using the code window
Creating a basic subroutine (Private Sub) for a control
Using the MsgBox function to display messages
Changing the Caption property for command buttons
Renaming controls and updating corresponding event procedures
Naming conventions for controls
Setting the Text property of text boxes
Adding code to update a text box from a button click event
Using comments to document code in VB
Creating a new project in Visual Basic
Restoring missing development environment windows
Adding multiple text boxes and command buttons
Copying and pasting controls to duplicate them
Naming text boxes and command buttons appropriately
Concatenating strings using the & operator
Setting captions for buttons and labels
Changing form and control properties (color, font)
Adding and editing labels for controls
Adding an Exit button with the End command
Building a simple calculator: planning and layout
Adding and naming input text boxes and output text box
Adding a Calculate button and coding its function
Understanding string concatenation vs numeric addition
Using the Val function to convert text box input to numbers
Debugging and correcting code to ensure proper addition
 
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 4/30/2026 9:52:52 AM. PLT: 1s
Keywords: VB QuickStart 1  PermaLink  How To Create Forms, Add Controls, Write Basic Code, and Concatenate Strings in Microsoft Visual Basic