0 ratings0% found this document useful (0 votes) 48 views21 pagesIntro To Visual Basic
Visual basic quick review handout for o level students
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
No Goggle, VB is, ja
jjecle more advanced than Small
atc jusclike Wordpad is more
“yavanced chan Notepad.
NATE Pi
Goggle Me Can you explain,
more about VB to
me, Toggle?
- No, Toggle! Today
=" ma'am told us we will be learning
about a new software called Visual
Basic. [know about Small Basic Are,
“...__ the two very different? _.
oo
You have learnt quite a bit of Small Basic by now. As you
know, Small Basic programs are executed one command
after another (i.e. sequentially). You type in the commands
(or methods) and you see the output of a program in a
TextWindow (working with text) or a GraphicsWindow
(working with lines and shapes) object.
Visual Basic (VB) is similar to Small Basic but has many more BDRM en eeay ies
r fretne
EW erie ian eases
features.
Visual means that it uses a Graphical User Interface (GUI)
to create programs, and Basic means that the language is based on the BASIC programmin
language.
In this chapter, you will learn Visual Basic 2013 Bx re
i i) ess. Iti
Microsoft supplies free for students and beginners, i “vecescal USER INTERFACE
ic has a Graphi
bl sa Graphical User Interface (
"windows icons, buttons, menus, ai
ems written with Visual Basic ha Hl
ve a
ane
(GUD
boca ote ame suagests, GUI software
Sree All these are called controls. All
User Interface. So Visual Basic has a GUI
ogt@l fi sd
iron" for writing programs,
ent priven Programming
al Basic programming is event-dri
si the mouse, double-cli nt-driven programming. A F
ickiN8 7 Clicking the mouse. a 1B. Re event is an action. For example,
i ing the mouse, sel i
set performs an action on , selecting an item from a list,
jreall actions. When the u
ent has occurred. a graphical component, we say an
wvent-driven programming,
sll Basic. The user ee eae Tesponds to events. It does not run step-by-step as
pendently: We write the code @n any eontol at anytime, so each contri programmed
i will be executed in response to different actions (events).
i TING STARTED WITH VISUAL BASIC
art Visual Basic, the steps are:
Click Start > All Programs (Fig. 5.1(a)] > Visu: 4
a al Studio 2013 5.
I for Desktop IFig. 5.1(0)l- dio 2013 [Fig. 5.1(b)] > VS Express 2013
Fig. 5.1 Steps to start VS Express 2013 for Desktop
>. The Visual Studio screen appears (Fig. >):
Microsoft Visual Studio
After a few seconds, the Start Page —
indow appears (Fig. 5.3)-
Express 2013 for Windows Desktop wi
Fig, 5.2 Visual StudioALE com view PROIECT
- 6/8 sat!
Search Toelbox
All Windows Forms
4 Common Controls
he Pointer
@ Button
CheckBoe
CheckedListBox
ComboBox.
DateTimePicker
B
a
A ube
A
a
LinkLabel
UstBox
Lstview
(Qs MaskedTetBox
© MonthCalendar
Fig. 5.6 IDE window with Toolbox
Click the Pin the tab button, the form will move to the right so that the Toolbox ang thes
are visible together (Fig. 5.7).
ick Laun tC
PRY Het icrosot Visual Studio Express 213 for Windows Desktop CCR Quick Launch (Ce
FILE EDIT VIEW PROJECT BUILD DEBUG TEAM TOOLS TEST WINDOW HELP
~8- 9/8 S/O -C-| > sun- [oa J[ayou__-|| Bele S
> 9 x SORE’
Search Toolbex
» All Windows Forms
4 Common Controls
Pointer
Button
CheckedListBox
B Combobox
EE DateTimevicker,ponents of the Visual Basic Windo
i wy
om veer Ow has many components
jn Figure > Figure 5.6, Ns, asyoutan ase
Top Tip
par: The title bar at the to
of the project (Fig. 5.8). By neat 4
dowsApplicationl, WindowsApy fi
wo here tS ‘Hello’ as per the ae é
nt 5.071 Page 69: Be
ino displays the
Names your projects
ation2, etc. The name
we had made in
Hello - Microsoft Visual Studio Express
2013 for Windows
Desktop as |
a Fig. 5.8 Title Bar
Above the Form: The tab at the t
l i (op of the form contains th Fomivopaan = *)
mt and [Design]. This means that the application has be ‘oie cl
urently in Design mode (Fig, 5.9). raleoie b
ig. 5.9 Form tal
Bar and Toolbar: TI :
a ofthe menubar ae consists of many drop-down menus. Clicking on any
ra options (Fig.SH10) ive. The toolbar has buttons that provide shortcuts to some
ept VIEW PROJECT BUILD DEBUG TEAM FORMAT TOOLS TEST WINDOW HELP.
co O/B EM MID Co) bSet-oan vou iia tele = ed
Fig. 5.10 The Menu bar and Toolbar
m Window: The Form window is the primary
rk area that forms the background of the
lication. The user can place objects on the form
511). |
box; The Toolbox contains the controls. Controls
GUI components that can be added to the form.
e commonly. used controls are Label, Button,
mboBox, ListBox, PictureBox, and TextBox
The Solution Explorer window
rent project Fig. 5.11 Form window
Top Tip
perties Window: A form can have many controls
h some properties.
it. Every control is associated witve a VB
The steps to create, execute, and sa’
application that does this are:
New
_ on the Start pase The
1. Click New Project.
Project window appears.
Under Installed > Templates, oer
Select Windows Forms Applicatio “pete
pane. At the bottom of this Coy oa 3
default project name WindowsAPPIIC* "Ay
and click OK.
some other name, say Message,
The IDE window will appear.
. Notice the name of the project,
title bar. The project has one form, nam
by default. Make sure Formt is selected.
4. Add a Button control to the form.
Select the form and make the following changes
in the Properties window:
* To change the title displayed on the form:
the box to the right of Text in the Properties
window and type Message (Fig. 5-19).
Notice that it appears on top of the form.
© To change the background colour of the form:
Click the box to the right of BackColor.
A drop-down menu arrow will appear. Click
the arrow and select Highlight (Fig. 5.20).
6. Select the button control by clicking it, and make
the following changes in the Properties window:
* Change Text to DisplayMessage (Fig. 5.21).
* Click the box to the right of Font, and then on
the button with three dots (Fig. 5.22).
The Font window will appear (Fig. 5.23). Set
Font to Tahoma, Font style to Bold and Size
to 12. Click OK. Notice that the default font is
Microsoft Sans Serif.
7. Follow these steps to write the code:
* Double-click the button control. The code
Is)
Message, in the
ed Form!
w
wi
m: Click
item Windows Feo
For
renrjenl eae z
rrotetLayout False
right a
eau False
Folze
plow 0¥0P
‘autoValidate: Enable,
ContetMenutP (cone)
poublebutered Falce
Enabled Toe 7
ert raced wit the conte
Fig. 5.19 Text property of
Cet
Ee
oo
=
ae
rn een
Cursor EB GrayTet
To ightightTet
BackColour HB HotTrack
Fig. 5.20 BackColor proj
Button System. Windows Forms Button
le le |e
ImageKey, TG one,
Imagelist (none)
RightToLeft No
The test associated with the control,
Fig. 5.21 Text propel
window will appear (Fig. 5.24), Italready has a code template. You will ad
code to this.Private stb] Due oni GHice ccemten fet eem
ati (
7
End Sub As EventArgs) Handles Buttont.click
Fig. 5.24 The code window
| ° ‘Type the code between the lines Private Sub and End Sub as shown in Figure 5.25.
ublic Class Form)
Msglox("Visual Basic is interesting!”)
i Private Sub Buttonl Click(sender As Object, e As Eventargs) Hondles Buttton1 Click
|___end_sub
Fig, 5.25 Visual Basic code
. To save the VB application, select FILE > Save All. This first saves the form and then the
project. The file extension for forms is vb. The extension for projects is .vbpro).
lication, Click DEBUG > Start Debugging. Or Press F5. Or Click th
To run the aj
wren [ge on the toolbar.
p. This will run your first Visual Basic
labeled DisplayMessage will appe
isplay a message box stating Visual
ve Start
program. A form titled Message with a single button
ar on the screen (Fig. 5.26).
dit will d | Basic is interesting} (Fig. 5.27).10
2, Click B
2 C
| ress
3, The
TV
pAKING WITH VARIABL
les
+ shot
+ must noqh jingle
t hold:
um!
IK m:
ilu
lent. The general
lent statement
isual Basic but W' il
sles in one line, separa?
« Integer, Percentage
ariable of the same d:
Integerhe cursor WI II be
|
Vote: Data
umber so th
Pre
sum of.
window are t
‘toolbar, the
Propertie
windowition Explorer ii
ents of the Visual Basic II