Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
46 views

Learn Visual Basic Version 6: Part 2: The Two Button Form in Detail

The document provides step-by-step instructions for creating a basic Visual Basic program with two command buttons. It describes starting Visual Basic, adding two command buttons to a form, naming the buttons, adding code to each button that displays a message when clicked, and running the program. The document then continues to provide more detailed explanations and additional learning resources for Visual Basic.

Uploaded by

beigna
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views

Learn Visual Basic Version 6: Part 2: The Two Button Form in Detail

The document provides step-by-step instructions for creating a basic Visual Basic program with two command buttons. It describes starting Visual Basic, adding two command buttons to a form, naming the buttons, adding code to each button that displays a message when clicked, and running the program. The document then continues to provide more detailed explanations and additional learning resources for Visual Basic.

Uploaded by

beigna
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

In the 'Essentials' topic Learning Visual Basic, a program that uses one form with two

command buttons was introduced.

We're going to go through the complete steps to create this.


First ... in rapid fire ... the steps.
Then ... a more complete explanation.

1. Start Visual Basic. Usually, 'Start > Programs > Microsoft Visual Studio > Microsoft
Visual Basic 6.0'.
2. Click the default Standard EXE icon and then click the Open button.
3. Click the Command Button icon in the Toolbox. Draw two buttons on the form by
clicking and dragging.
4. Click the first Command Button to select it. Open the property window and change
the Name property to CommandA. Change the Caption to A.
5. Select the second Command Button from the drop down window at the top of the
property window and then change the Name property to CommandB. Change the
Caption to B.
6. Double click the first Command Button object in the form to open the code window
for that button.
7. Enter the code, Msgbox "You clicked Button A" after the automatically entered code
Private Sub CommandA_Click().
8. Double click the second Command Button object in the form to open the code
window for that button.
9. Enter the code, Msgbox "You clicked Button B" after the automatically entered code
Private Sub CommandB_Click().
10. Click the Run button in the toolbar at the top of the VB 6 development environment
window to execute the program.
11. Click either button A or button B and observe the fruits of your labor!

Learn Visual Basic Version 6 Part 2: The Two Button Form In


Detail

In the previous page, we went through the 'Two Button Form' at


Internet speed. We're going to look at it in detail and explain all
the steps this time.

Step 1 and Step 2

Start Visual Basic. Usually, 'Start > Programs > Microsoft Visual Studio > Microsoft Visual
Basic 6.0'.
Click the default "Standard EXE" icon and then click the "Open" button.

You should see the opening dialog window as explained in Learning Visual Basic. Check that
page out for more.
Step 3

Drag a 'Command Button' from the 'Toolbox' to the form and drop it. Drag another one to
the form and drop it.

The VB 6 development environment is designed to let you constantly change the


components that are visible so you can work with only those windows that apply to the
problem at hand. The 'ToolBox' is one of those components and may, or may not, be visible
in your system. The 'Toolbox' looks like this: (The tools that are in the toolbox can change
too!)

If you can't see the toolbox, look for it in the 'View' menu. And notice that several other
components can be turned on and off there, too. Some that you will use are:

 Project Explorer
 Immediate Window
 Locals Window
 Watch Window

Another thing to know is that VB 6 uses the right-click 'context menu' a lot. Right click
'Form1' for example and notice the options there. This is the fastest way to switch between
viewing an object (like Form1) and the code in that object.
Learn Visual Basic Version 6 Part 3: Finishing the Two Button
Form

In the previous page, we actually completed the design of the


form for our project ... which only consisted of dragging two
command buttons to the form. In this page, we change their
names, add the event code for both buttons and actually run the program.

Steps 4 and Step 5

Click the first Command Button to select it. Open the property window and change the
Name property to CommandA. Change the Caption to A.
Select the second Command Button from the drop down window at the top of the property
window and then change the Name property to CommandB. Change the Caption to B.

The new thing in this step is 'Open the property window'. Remember the 'right click context
menu' from the previous page? Try right clicking the first command button and you will
see ...
Click 'Properties' at the bottom to open the window. Then click the 'Name' property in the
first column and change the value in the second. We do this because we want to use unique
names in our program code to refer to this object. Visual Basic will do it automatically (it
already has) but it's hard to keep track of a series of objects with names like 'Command1',
'Command2', and so forth. You might also notice that the Property window is dockable and
resizable. It's been undocked and resized below:

Steps 6, 7, 8, and 9

Double click the first 'Command Button' object in the form to open the code window for that
button.
Enter the code,

Msgbox "You clicked Button A"

after the automatically entered code


Private Sub CommandA_Click()

Double click the second 'Command Button' object in the form to open the code window for
that button.
Enter the code,

Msgbox "You clicked Button B"

after the automatically entered code

Private Sub CommandA_Click()

Notice that a subroutine has already been entered into the code window automatically. VB 6
helps out as much as it can! All you have to do is enter your code inside the subroutine. It's
worth knowing that all of the code is actually saved in the form object. VB has to organize
the files for your project and that just happens to be where it is. If you have independent
module code (code that might be used anywhere your program, rather than just for one
particular object and event), it's saved in a different object. Another thing to notice is the
'naming convention' used for the subroutine:

CommandA_Click

This is always the same. The first part is the name of the object. The second part is the
event. You can't change this name or VB won't know where to find your event code. Let VB
assign these names and leave them alone.

Steps 10 and 11

Click the 'Run' button in the toolbar at the top of the VB 6 development environment
window to execute the program.
Click either button A or button B and observe the fruits of your labor!

The only confusion factor here might be, "Where is this 'Run' button?" The answer is, "Right
Here ..." (You can also find this on the 'Run' menu.)

If you still think you need some more help getting up to speed, check out some of the other
web pages in the links on the next page.

Learn Visual Basic Version 6 Part 4: Other Sources for Learning


VB 6
One really great advantage of deciding to learn VB 6 is that the world has had time to
develop top notch tutorials. There are really more of them than you have time! We're here
to help you solve that problem by selecting the good ones so you
don't have to spend your time on the others. You can find a
concise set of the best pages here that will get you up to speed on VB 6. Go through this list
of pages thoroughly, and then print a diploma for yourself. You're a VB 6 programmer!

Moving Up to Objects

At about this time, a few experienced programmers reading this will be shouting, "VB 6 is
not object oriented!!"

Mmmmmm ... Yes it is.

This has got to be one of the great religious struggles in programming. Although the wars
don't rage like they once did, some people have rigidly defined definitions of exactly what is,
and is not, object oriented and according to those definitions, VB 6 and predecessors do not
make the grade. Others, including me, take the view that "object oriented" is a concept,
and not a set of rules. VB 6 is clearly object oriented in concept.

Visual Basic and Data

The first thing you need to know about is databases and one of the best to start with is
Access, Microsoft's database for non-server environments. The About.com 'Databases' site
has an excellent article about Access

When you have created (or borrowed ... several great example databases are available
along with VB and Access from Microsoft) a database, the next thing to do is use the Data
Control object to read and write the data. An article about how to do that with Microsoft's
latest data technology.

Visual Basic and Active Server Pages

Another more advanced technology that you can use with VB 6 is called Active Server
Pages, or ASP. This is the technology that allows you to run your VB 6 system on an IIS
web server and server HTML pages controlled by your programming over the web. You can
find an introduction to doing that in a VB 6 environment.

When VB.NET was introduced, Microsoft put millions into the advertising budget because
they were very worried about the competition. They really were not sure that .NET could
measure up. The competition is VB 6

You might also like