What Is Visual Basic and Why Do I Need It?
What Is Visual Basic and Why Do I Need It?
What Is Visual Basic and Why Do I Need It?
Lecture Notes
Week1
Visual Basic suits more for application developing than for Games developing.
You can create sophisticated games using Visual Basic, But
If you want to make a really advanced professional game like Quake 2,
You may choose other language (like C++), that would be much more
harder to program with.
However, Visual Basic will be probably powerful enough to suit all your application
and games programming needs.
1 / 18
CTP108 - Programming for Business
Lecture Notes
Week1
Getting Started
Note that all the images in this tutorial taken from Visual Basic version 6.0.
If you using other version of Visual Basic, the images that you will see may
be a little different.
Run the Visual Basic program. The first thing you see is:
Figure 1
Here you choose what is the kind of the program you want to create.
For creating a simple Visual Basic program, choose the Standard EXE,
and press the Open Button.
(If Figure 1 is not the first thing you see when you run Visual Basic,
choose from the Visual Basic menu File->New Project (Figure 2))
2 / 18
CTP108 - Programming for Business
Lecture Notes
Week1
Figure 2
Figure 3
3 / 18
CTP108 - Programming for Business
Lecture Notes
Week1
Figure 4
Figure 5
4 / 18
CTP108 - Programming for Business
Lecture Notes
Week1
To stop the program from running, you can click on the Stop button
in the Toolbar (Figure 6), or click the form's X button (Figure 7).
It's very recommended that you will always close your programs using the
form's X button instead of the Visual Basic Stop button.
It's like shutting Windows from the Start button, instead of Pressing
the Power button.
Figure 6
Figure 7
To see the form properties, select from the menu View->Properties Window (Figure 8).
5 / 18
CTP108 - Programming for Business
Lecture Notes
Week1
Figure 8
Figure 9
6 / 18
CTP108 - Programming for Business
Lecture Notes
Week1
The column marked by the blue circle contains the form's property names:
The form has Name property, Appearance property AutoRedraw property, and more.
The column marked by the black circle contains the form's property values:
The form's Name is Form1, The form's Appearance property is 1 - 3D, and so on.
To change the Caption property, simply click on the Caption property in the
form's properties names column (Figure 10).
Figure 10
7 / 18
CTP108 - Programming for Business
Lecture Notes
Week1
Figure 11
Now run the program using the Play button (Figure 4).
You will see that the text on the form's Title bar is Hello (Figure 12).
Figure 12
8 / 18
CTP108 - Programming for Business
Lecture Notes
Week1
Figure 13
Figure 14
9 / 18
CTP108 - Programming for Business
Lecture Notes
Week1
Figure 15
As results, the Command Button icon will look pressed (Figure 16).
Figure 16
10 / 18
CTP108 - Programming for Business
Lecture Notes
Week1
Now click on the form with the left mouse button, and hold the button
down while moving the cursor.
You will see a rectangle.
Release the mouse button, and in the place of the rectangle you
will see a button (Figure 17).
Figure 17
Figure 18
11 / 18
CTP108 - Programming for Business
Lecture Notes
Week1
Figure 19
As you can see, In the top of the properties window, right under the title bar,
appears "Command1 CommandButton".
Command1 - because it's the name of this specific Command Button (look
at the name property).
If you want you can change the Name of any component, by simply
changing the component's Name property.
Change the Command Button's BackColor property to blue (or other color).
The change won't take affect, untill you will set the Command Button's Style
property to 1 -Graphical.
12 / 18
CTP108 - Programming for Business
Lecture Notes
Week1
You can now play a little bit with the Command Button's properties,
this is the best way to learn what every property does.
You can also add other controls from the Toolbox to your form,
And play around with their properties.
Figure 20
13 / 18
CTP108 - Programming for Business
Lecture Notes
Week1
MsgBox "Hello"
Will launch a message box with the text "Hello".
Insert the line MsgBox "Hello" to the Form_Load event (Figure 21).
Figure 21
Figure 22
More Events
The Form has more events besides the Form_Load event.
How can you find them?
14 / 18
CTP108 - Programming for Business
Lecture Notes
Week1
Click on the Drop-Down List that found in the upper left corner of
the Code Window, where appears right now the text "Form" (Figure 23).
Figure 23
You will see a list of the components that found in your program.
You have 1 command button with the name "Command1" and 1 Form.
Here you select which component's event you want to program.
We want to program a form's event, so select "Form" from the list (Figure 23).
Figure 24
15 / 18
CTP108 - Programming for Business
Lecture Notes
Week1
and this happening when you close the program (Using the form's X button (Figure 7)).
So the code that you will write in the Form_Unload event will be launched
when you close the program.
MsgBox "GoodBye"
After you inserted this line to the Click event the Click event should look like this:
As you can see, the Command Button's Click event called "Command1_Click",
because the name of the specific Command Button that we program
its Click event is "Command1".
If we had program the Click event of a Command Button with the
name "BlahBlah7", the Click event would be called "BlahBlah7_Click".
Every component has its own unique events, therefore if you had
5 Command Buttons on your form, every one of them has its
own unique Click event.
Print "Hello"
Figure 25
Figure 26
17 / 18
CTP108 - Programming for Business
Lecture Notes
Week1
Now, rewrite the Command1 Click event and insert the
following line to it:
After you've done so, your code should look like this:
18 / 18