Ics 2209-Introduction To Visual Basic
Ics 2209-Introduction To Visual Basic
Microsoft's Visual Studio (Visual Studio.NET) is a suite of products that includes the .NET Framework and
the Integrated Development Environment (IDE). The .NET Framework supports several different programming
languages, which includes: Visual Basic, Visual C# (C sharp), C++ (cee-plus-plus), Visual F# (F sharp) and
Web Development (ASP.NET). These languages compile i.e. they are translated from human readable-form to
machine readable-form to the same Microsoft Intermediate Language (MSIL).
MSIL run within the Common Language Runtime (CLR) – a component of the .NET Framework.
VB is available in several editions including the free Express Edition that is downloaded from
Microsoft. Other editions are Professional, Premium, and Ultimate.
VB supports programming projects that run in both:
Console Applications
Windows Applications
Web-based, Client-Server Applications
Visual Studio
You will use the VB component of Visual Studio to create and test projects.
The programming applications you will design and develop are called solutions i.e. each Application
that you create is organized by Visual Studio into a Solution
.NET Framework
In order to work with VB, you need to understand "object" terminology as defined below.
Terminology Definition
Object An entity – like a noun in English. Examples include forms and controls
you place on forms such as buttons, text boxes, and icons.
Property Objects have properties – like adjectives in English. Properties describe
object behaviors. Examples of properties include Text, Name, BackColor,
and Size. Refer to a property by the notation ObjectName.PropertyName
example: TotalDueTextBox.Text
This table gives examples of both the Camel Casing and Hungarian naming conventions.
Note: Label controls are often not renamed – they are not referred to later in writing computer code so the
default assigned name is unchanged.
Sample Application
Design and code the following sample application
Integrated Common
Visual Basic
Development Language
compiler
Environment Runtime
1 2 3
Solution Assembly
Project
Intermediate Language (IL)
Source files
Class references
Program Coding
Programming or writing program code is the means used to cause something to happen when an event, such as a
button click occurs.
The Handles clause indicates that this sub procedure handles the Click event of the button named
Display1Button. Generally, Visual Studio “wires” an event to a handler using the “handles clause” in the
handler header
The sub procedure ends with the line of code End Sub.
Each sub procedure must have a unique name – VB generates a name by combining the name of the
control + an underscore + the name of the event, e.g., Display1Button_Click.
Each sub procedure has two parameters inside of the parentheses that accompany the event name – these
are named sender and e.
The form named StudentInfo is created as an instance of the general Form object defined in the .NET
Framework class library.
It is declared by the Public Class StudentInfo statement.
The End Class statement marks the end of the form's class definition.
Event Handlers
An event handler is a procedure containing statements that execute when the end user performs an
action. Activity happens when an event is fired.
o Windows executes different event handlers as different events fire
o Windows fires a Click event when the end user clicks a button
o Different types of controls support different events
Notice that when an event is fired we get another process running – the event handler
Note: Remark statements before the Public Class statement are used to identify the project, the programmer,
and the date the program was written and must ALWAYS be included in the project.
' VB University
'Author name
'Today's Date
'Illustrates displaying information to read-only TextBox
'controls by clicking Button controls
Accessing Intellisense
VB's Intellisense feature makes it easier for you to type programming statements. To access Intellisense simply
begin to type the name of an object such as the NameTextBox – VB will pop up a window that displays
possible selections – this makes it easier for you to type code and leads to fewer typing errors.
Assign a student name to the Text property of the TextBox control named NameTextBox and a student’s major
to the TextBox control named MajorTextBox. The assignment statements to do this are:
Example
Private Sub ResetButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles ResetButton.Click
NameTextBox.Clear()
MajorTextBox.Clear()
End Sub
VB Help (MSDN)
The Microsoft Developer Network (MSDN) library contains books and technical articles to help you answer
questions that will arise as you learn the VB language.
MSDN can be access from a hard drive, network drive, or the Web (requires an Internet connection).
Hard drive installation is fastest and most convenient.
Web access is from http://msdn.microsoft.com.
You can also obtain context-sensitive help on an object by placing the insertion point in a word in the coding
editor or by selecting a VB object and pressing the F1 function key.
Complete Solution
'Ch01VBUniversity
'Today's Date
'Illustrates displaying information to read-only TextBox
'controls by clicking Button controls