0% found this document useful (0 votes)
87 views

TekHigh-Visual Basic - Net (2021!12!24 13-09-30 UTC)

Here are the step-by-step workings: 1) Evaluate the sub-expression inside the parentheses first: x = 5 2) Apply the relational operator: 5 > 3 is True 3) Apply the logical operator: NOT True is False So the overall evaluation of the expression NOT (x > 3) is False.

Uploaded by

Dondon Mendez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
87 views

TekHigh-Visual Basic - Net (2021!12!24 13-09-30 UTC)

Here are the step-by-step workings: 1) Evaluate the sub-expression inside the parentheses first: x = 5 2) Apply the relational operator: 5 > 3 is True 3) Apply the logical operator: NOT True is False So the overall evaluation of the expression NOT (x > 3) is False.

Uploaded by

Dondon Mendez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 230

VB.

NET
Lesson 1:
Introduction to
Computer
Programming
Objectives:
By the end of this courseware, the student
is expected to:

1. Discover the history behind computer


programming
2. Analyze the differences between
programming languages.
3. Analyze the patterns of programming in
Visual Studio.IDE.
What is Program?
Program is a set of instructions that
perform a specific task.
Programming is a process of doing a
program that the computer can
execute in sequential manner.
Computer Program is an executable
program that can be installed in the
computer to be used by the end users.
Programmers these are the people who
assigned in doing any computer
programs.
Programming Languages – These are the
tools that can be used by the
programmers to develop a certain
computer programs.
Examples of Computer
Programs
1. Microsoft Windows Operating
System (OS) – System Software

2. Word Processing Program of


Microsoft Office and
OpenOffice - Application Program
Examples of Computer
Programs
3. Computer programs are also used for
entertainment—from watching movies
to playing an online roleplaying game
(RPG).

4. Programs run in point-of-sale (POS)


vending machines every time someone
makes a purchase from
them.
Examples of Computer
Programs
5. Traffic Light
6. Automatic Teller Machine (ATM)
7. Ultrasound
8. X-Ray Machine
9. Counter Strike
Examples of Computer
Programs
10. Dota
11. Payroll System
12. Antivirus Norton
13. Defragmentation
14. Scandisk
Generations of Programming
Languages
1. First Generation (1GL) - Machine Language

2. Second Generation (2GL) – Assembly


Language

3. Third Generation (3GL) – High Level Language


Translation of Programming
Languages
Translation can be done in two ways:
1. Interpreter - is a program that
translates high-level language
instructions into machine code, line by
line, during program execution.
2. Compiler - translates high-level
instructions into machine code before
program execution.
The .NET Framework and
Visual Basic
.NET (Dotnet) and Visual Basic were
created to enhance and complement
the Microsoft Windows operating
system.
The History of Computers
• Altair System rocked the world of
businessmen – Gates & Paul Allen

• BASIC – Beginners all purpose


Symbolic Instruction Code
The History of Computers
• IBM launched personal computers
running under Microsoft Disk
Operating System MSDOS

• The Sun Microsystems Java


programming language was a rising
star in the 1990s, and the free
operating system.
Consistent Programming
Models
• Programming languages have
different ways to do the same thing.
With .NET, programming languages
for the Visual Studio platform, such
as Visual Basic, Visual C++, and
Visual C#, can use the same classes
to do a certain task.
Syntactic Elements
1. Security Enhancement – Can run in
different variety of machines.
2. Simplified Development - how objects
and user interfaces are displayed to the
software user
3. Easier Application Deployment –
converting the program into an
executable one.
Microsoft Visual Studio
Visual Studio is an integrated
development environment (IDE)
that is used to develop computer
programs running under the
Microsoft Windows environment
such as the Windows Operating
System, Windows Mobile, and
Microsoft Silverlight.
IDE Components
• Source Code Editor
• Compilers and Interpreters
• Build Automation Tools
• Error Debugger
Brief History of Visual Basic
• Alan Cooper was considered as the
Father of Visual Basic
• Visual Basic was the combination of
two languages namely, Basic and
Ruby means Visual.
Brief History of Visual Basic
• The version one of Visual Basic was
developed in 1991 followed by
version 2 in 1992.
• Visual Basic is the first programming
language involves the graphical
user interface.
Visual Basic.net Screen
Solution
Explorer

Toolbox
Windows
Form
Designer

Data Properties
Sources Window
Window
Error List
Window

Visual Basic 2010 IDE


Parts of the VB.Net Screen
1. Title Bar
2. Menu Bar
3. Toolbar
4. Toolbox
Parts of the VB.Net Screen
1. Windows Form Designer/Code
Window
2. Solution Explorer
3. Data Sources Window
4. Error List Window
Lesson 2:
Front End Application
Objectives:
In this lesson, the students will be able to:

• Apply basic controls of VB.NET.


• Design and implement variables with
different data types.
• Design simple to complex user interfaces
using Form and Control techniques.
Visual Basic .NET 2010 Express Edition Start Page
Visual Basic.net Framework
Default Project Templates
• Windows Form Application
• WPF Application
• Console Application
• Class Library
• WPF Browser Application
Saving your Project
• To save your progress, click on the
Save All icon or go to File > Save All.
A new window will appear with the
basic details of your project.
Saving your Project

Save Icon
Save Project Dialog Box
Checking if the project is saved
properly
1. Go to File > Close Project, which
will clear the VB work area.
2. Then go to File > Open Project. A
file browser window will pop up
and ask you to select the folder of
the project.
Checking if the project is saved
properly
1. Choose the project file as the
Object Name and then click on the
Open button.
2. If the project was saved
successfully, the VB.NET IDE will
load the project you were working
on in the exact way that you had
left it.
Forms and Controls

Form and Toolbox


Common Controls
CREATING A SIMPLE
APPLICATION

DISPLAYING “HELLO WORLD!”


THREE STEPS IN CREATING
A PROGRAM IN VB.NET
1. Creating or designing an Interface

2. Setting the properties of each control


found in the interface

3. Writing the codes


Designing an Interface
Setting Properties
Controls Property Setting

Form1 Text My First Application


BackColor ForestGreen
Label 1 Text Name:

Textbox1 Text Empty

Button1 Text Submit


Writing the Codes
Public Class Form1
Private Sub Button1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
TextBox1.Text = "Hello World"
End Sub
End Class
How run the program
Just click this icon in a toolbar,
if the codes are correct, the output
will display in your screen, or
simply press F5
Output:
Lesson 3:
Back End Application
Objectives:
In this lesson, the students will be able to:
• Identify the uses of different data types in
VB.Net.
• Design and implement variables with
different data types.
• Program a simple application by merging
the user-interface with the code through
events.
Elements of Visual Basic.Net
• Keywords
• Identifier
• Variable
• Data Types
• Numeric
• Non numeric
• Variables are used to temporarily store
data when an application is running.
• These should have a name and a data
type.
• To declare a variable, the Dim statement
is used.
• An event is a signal that the user has
done something with the controls and
the form.
Rules in Naming an Identifier
• Assign meaningful names that are easy to
remember.
• Start each variable name with a letter of the
alphabet or underscore.
• Do not use spaces or symbols.
• Do not use keywords such as Boolean or any
data types
• Use PascalCasing or camelCasing when
naming variables composed of more than two
words.
Data Types
Two Data Types of Visual Basic
• Numeric
• Non numeric
Numeric Data type
Non numeric Data type
The Event Procedure
Programs made in Visual Basic, or
those that can simply be called
“window” applications, are
event-driven programs.
Merging the Front End and Back
End Applications
To do this, you must do two things:

• Assign the value of the Text Box to a


variable.
• Select the “Click” event for the
button.
Double-click the Submit Button

Code Snippet for Button Click Event


• Private means that no other part of the code
can see the code within Private Sub and End
Sub block other than the button.
• Sub is a shortcut for subroutine, which tells
Visual Basic that there are lines of code
following it that need to be executed.
• _Click() is the event; in this case the specific
event is for the button to be clicked.
• End Sub signifies the end of the subroutine
code block.
Let’s modify the previous example in
displaying your complete name
Designing an Interface
Setting Properties
Controls Property Setting
Form1 Text My First Application
BackColor ForestGreen
Label 1 Text Name:
Name lblMessage
Label 2 Text Empty
Name lblName
Textbox1 Text Empty
Name TbxName
Button1 Text Submit
Name btnSubmit
Writing the Codes

Full Code Snippet


Application Output
Lesson 4:
Operators
Objectives:
In this lesson, the students will be able to:

• Design operators from simple to


complex expressions in VB.NET.
• Solve different problems using
appropriate control structure solutions.
Types of Operator
• Arithmetic operator
• Relational Operator
• Logical Operator
Arithmetic Operator
Relational Operator
Logical Operators
Truth Table of Logical Operators

Truth Table for OR Operator


Truth Table of Logical Operators

Truth Table for XOR Operator


Truth Table of Logical Operator
Expression (NOT)Result

Not(True) False

Not (False) True


Instructions:
Evaluate this expression if the
result is true or false:

Not(4+10)* 2<3mod5 and 6+2 <> 8 or 90>15/3


Concatenation Operators
Concatenation operators are used to
join two expressions. There are only
two kinds of concatenation
operators, “&” and “+” and they
perform the same action.
Control Structure
Three Type of Control Structure
1. Sequence
2. Selection/Decision Structure
3. Repetition/Looping/Iteration
Structure
Sequence Structure
It executes the statements starting
from the first statement up to the
last statement sequentially.
Problem:
Create a program that will input three
integer numbers. Compute the sum
and the average of the three numbers.
Decision Structure
It executes two or more statements in the
programs

Types of Decision Structure


• If statement
• Select case Statement
If-Then Statement
Syntax:
If condition then
vb statement
End if
Example: Determine if the number
is odd or even
Public Class frmifStatement
Private Sub btnOk_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs)
Handles btnOk.Click
Dim number As Integer
number = Val(Txtnumber.Text)
If number Mod 2 = 0 Then
lbldisplay.Text = "It is an even number“
End if
If number Mod 2 = 1 Then
lbldisplay.Text = "It is an odd number"
End If
End Sub
End Class
SETTING PROPERTIES
CONTROL PROPERTY SETTING
Form1

Label1

Label 2

Textbox1

button1
Output
If-Then else Statement
Syntax:
If Condition then
Vb statement1
Else
vb statement2
End if
Example: Determine if the number
is odd or even using if else

Dim number As Integer


number = Val(Txtnumber.Text)
If number Mod 2 = 0 Then
lbldisplay.Text = "It is an even number"
Else
lbldisplay.Text = "It is an odd number"
End If
Else if Statement
Syntax:
If Condition1 then
Vb statement-1
Else if condition 2 then
vb statement-2
Else
vb statement-n
End if
Example:
Dim number As Integer
number = Val(Txtnumber.Text)
If number > 0 Then
lbldisplay.Text = "It is positive number"
Else if number <0 then
lbldisplay.Text = "It is negative number“
else
lbldisplay.text = “It is equal to zero”
End If
Output
Case Statement
Syntax:
Select case variable
Case 1
statement 1
Case 2
statement 2
Case else
statement n
End select
SETTING PROPERTIES
CONTROL PROPERTY SETTING
Form1

Combo1

Button1
OUTPUT
Lesson 5:
Loops & Arrays
Objectives:
In this lesson, the students will be able to:

1. Discuss the different parts of a loop.


2. Compare and contrast the different
types of loops and their uses.
3. Manipulate arrays using looping
structures.
Loops

It permit a set of instructions to be


repeated over and over again until a
particular condition is reached.
Two Kinds of Loop
1. While Loop
2. Do Loop
3. For Loop
While Loop
Syntax:
While condition
vb.net statements
End While
A diagram showing the While Loop structure
WRITING THE
CODES
Public Class whileLoopAddBetweenNumbers
Private Sub btnSubmit_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnSubmit.Click
Dim StartNoDisplay As Integer 'empty variable
Dim StartNo As Integer = NumericUpDownStart.Value 'store the
start number
Dim EndNo As Integer = NumericUpDownEnd.Value 'store the
end number
Dim ResultNo As Integer = 0 'empty variable to store result
StartNoDisplay = StartNo 'make two copies of the start number
While StartNo <= EndNo 'begin while loop
ResultNo = ResultNo + StartNo 'and the numbers together
StartNo = StartNo + 1 'go to the next number
End While 'end while loop
MsgBox("The sum of all the numbers between " &
StartNoDisplay & " and " & EndNo &
" is " & ResultNo)
End Sub
End Class
OUTPUT:
SETTING
PROPERTIES
CONTROLS PROPERTY SETTING
Do Loop
Syntax:
Do while condition
vb.net statements
Loop
Example: Do While Loop
Do While StartNo <= EndNo
ResultNo = ResultNo + StartNo
StartNo = StartNo + 1
Loop
Do Loop
Syntax:
Do
vb.net statements
Loop while condition
Example: Do While Loop
Do
ResultNo = ResultNo + StartNo
StartNo = StartNo + 1
Loop While StartNo <= Endno
Do Loop
Syntax:
Do until condition
vb.net statements
Loop
Example: Do Until Loop
Do Until StartNo - 1 = EndNo
ResultNo = ResultNo + StartNo
StartNo = StartNo + 1
Loop
Example: Do Until Loop
Do Until StartNo - 1 = EndNo
ResultNo = ResultNo + Start No
StartNo = StartNo + 1
Loop
Do Loop
Syntax:
Do
vb.net statements
Loop until condition
Example: Do Loop Until
Do
ResultNo = ResultNo + Start No
StartNo = StartNo + 1
Loop Until StartNo - 1 = EndNo
For Next
Syntax:
For var = start to end
vb.net statements
next
Example: For Next
For StartNo = StartNo To EndNo
ResultNo = ResultNo + StartNo
Next
ACTIVITY:
Sample Problems
Create a program that will display
the ff:

1. Input your name and display 10


times
2. Display numbers 1 to 100
3. Display multiplication table.
Array Concepts
An array is a collection of values of
identical data type referenced under
one name.
The variables in an array are called
array elements, which are accessed
using a single name and index
number representing the position of
the element within the array.
Declaring an Array
Dim ColorRed() As String = New String() {“Apple”, “Strawberry”, “Tomato”,
“Cherry”}
Dim ColorYellow() As String = New String() {“Banana”, Mangoes”, “Lemon”, “Corn”}
Dim ColorOrange(4) As String
ColorOrange(0) = “Orange”
ColorOrange(1) = “Papaya”
ColorOrange(2) = “Carrot”
ColorOrange(3) = “Pumpkin”
Dim ColorViolet(4) As String
ColorViolet(0) = “Grape”
ColorViolet(1) = “Eggplant”
ColorViolet(2) = “Raisin”
ColorViolet(3) = “Plum”
Retrieving Contents of an
Array
Dim ColorRedElementList As String = “ ”
For lngPosition = LBound(ColorRed) To
UBound(ColorRed)
ColorRedElementList = ColorRedElementList
&
ColorRed(lngPosition) & “, ”
Next
MsgBox(ColorRedElementList)
Adding Elements to an Array
Dim ColorRedElementList As String = “ ”
Dim ArrayCounter As Integer = 0
Do While ArrayCounter < ColorRed.Length
ColorRedElementList = ColorRedElementList
&
ColorRed(ArrayCounter) & “, ”
ArrayCounter = ArrayCounter + 1
Loop
MsgBox(ColorRedElementList)
Interface
Writing Complete Codes
Private Sub btnSubmit_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs)
Handles btnSubmit.Click
Dim UserInput As String = ""
UserInput = txtUserInput.Text
If UserInput <> "" Then
If ColorGreenDec = False Then
ReDim ColorGreen(0) 'Change length of array
ColorGreenDec = True
Else
ReDim Preserve
ColorGreen(UBound(ColorGreen) + 1)
'Change length w/o deleting elements
End If
Dim CurrentPointer = UBound(ColorGreen)
ColorGreen(CurrentPointer) = UserInput
End If
Dim CurrentPointer = UBound(ColorGreen)
ColorGreen(CurrentPointer) = UserInput
End If
lblGreen.Text = "There are " & ColorGreen.Length
& "element/s in the Array."
listColorGreen.Items.Clear() 'Clear the
Listbox for use
Dim ColorGreenIndex As Integer
For ColorGreenIndex = LBound(ColorGreen)
To UBound(ColorGreen)
listColorGreen.Items.Add(ColorGreenIndex & "
-> " &
ColorGreen(ColorGreenIndex))
Next
End Sub
Setting Properties
Controls Property Setting

Form1

Label1

Textbox1

Listbox1

Button1
Global Variables
• These are declared in the general
declarations part of the code. They are
outside any subroutine or functions but
still within the class.
• These variables have a Public access
modifier which means that they can be
used by all elements in the project.
Lesson 6:
Organizing Your
Program using
Procedures
Objectives:
In this lesson, the students will be able to:

1. Organize the program using procedures.


2. Create and use a subroutine and function.
3. Use a module.
Procedure

It is a set of one or more program


statements that can be executed by
referring to the procedure name.
Subroutine
It is a block of code enclosed within
the Sub and End Sub statements.
Creating and Using Subroutines
Public Class formSubRtn
Public FirstName As String
Public MiddleName As String
Public LastName As String
Private Sub btnDB_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnDB.Click
FirstName = txtFirstName.Text
MiddleName = txtMiddleName.Text
LastName = txtLastName.Text
If FirstName = “” Or MiddleName = “” Or LastName = “” Then
MsgBox(“You have left a field empty.”)
End If
End Sub
Creating and Using Subroutines
Private Sub btnTxt_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnTxt.Click
FirstName = txtFirstName.Text
MiddleName = txtMiddleName.Text
LastName = txtLastName.Text
If FirstName = “” Or MiddleName = “” Or LastName = “” Then
MsgBox(“You have left a field empty.”)
End If
End Sub
End Class
Using Subroutines in the
Program
Public Class formSubRtn
Private Sub btnDB_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnDB.Click
Call checkEmpty()
End Sub
Private Sub btnTxt_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnTxt.Click
Call checkEmpty()
End Sub
Using Subroutines in the
Program
Public Sub checkEmpty()
Dim FirstName As String = txtFirstName.Text
Dim MiddleName As String = txtMiddleName.Text
Dim LastName As String = txtLastName.Text
If FirstName = “” Or MiddleName = “” Or LastName = “” Then
MsgBox(“You have left a field empty.”)
End If
End Sub
End Class
Setting Properties
Control Property Setting
Form1
Textbox1
Textbox2
Textbox3
Label1
Label2
Label3
Button1
Button2
Interface
Parameters

These are values that are passed to the


subroutine
EXAMPLE CODES:
Public Class formSubRtn
Public FirstName As String
Public MiddleName As String
Public LastName As String
Private Sub btnDB_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnDB.Click
FirstName = txtFirstName.Text
MiddleName = txtMiddleName.Text
LastName = txtLastName.Text
Call checkEmpty(FirstName, MiddleName, LastName)
End Sub
Private Sub btnTxt_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
btnTxt.Click
FirstName = txtFirstName.Text
MiddleName = txtMiddleName.Text
LastName = txtLastName.Text
Call checkEmpty(FirstName, MiddleName, LastName)
End Sub
EXAMPLE CODES:
Public Sub checkEmpty(ByVal NameFirst As String,
ByVal NameMiddle
As String, ByVal NameLast As String)
If NameFirst = “” Or NameMiddle = “” Or NameLast =
“” Then
MsgBox(“You have left a field empty.”)
End If
End Sub
End Class
CUSTOM MODULES
• Instead of writing the procedure in that
form, we can use a module so that all other
forms can share the procedures stored in it.
Let’s study how to create a module in Visual
Basic .NET.

• First, go to the Main Menu, click on Project


then select Add New Item.
CUSTOM MODULES
A new window will be opened which
allows you to select items that you can
add to your project. Select Module from
the list of Common Items.
ADDING NEW ITEM IN THE
FORM
ADDING MODULES
After selecting the module option and
giving it a name, a blank coding window
will appear, such as the one here.
Putting the function in the
module
Module ModDataCheck
Public Function checkEmpty(ByRef
checkThisData As String) As Boolean
If checkThisData = “” Then
Return True
End If
End Function
End Module
Output:
Access Modifiers
Access Modifiers
Access Modifier – defines the
accessibility of a procedure or function

Arguments – values passed to the


parameters of a procedure or function

Parameter – variables found within the


signature of a procedure or function
Lesson 7:
Introduction to
OOP in VB.NET
Objectives:
In this lesson, the students will be able to:

1. Discuss the key concepts of


Object-oriented programming.
2. Create programs utilizing properties,
events and methods in OOP
3. Demonstrate the 4 pillars of OOP
through programming practice.
Object Oriented Programming
Methodology of programming wherein
entities in the problem domain are
modeled in program code as objects
Visual Basic .NET is an OOP language
organized around objects (rather
than actions) and data (rather than
logic). For a programming language
to claim that it follows OOP, it must
have the following criteria:
abstraction, encapsulation,
inheritance, and polymorphism.
Principles of OOP in VB
1. Abstraction
2. Encapsulation
3. Inheritance
4. Polymorphism
Encapsulation
The other term used for encapsulation
is information hiding.
It hides the codes of the program
because the VB has the capability to
convert into an executable. Once you
compile the program, the extension
name .vp will be changed into .exe.
Inheritance
This allows the creation of new classes
from existing class definitions and
promotes code reuse.
Polymorphism
• Poly means many and phism means
form, so it can provide several
forms.

• This refers to a single interface with


multiple behaviors.
An object is an instance of a class. All
objects of a class have individual copies of
the attributes and share a common set of
behaviors.

The elements of a class are the following:


• Properties define the attributes of a
class, and represent data that are
relevant to the design of a class.
• Methods define the functionality of a class
or what a class can do.

• Events refer to the actuation of certain


conditions relevant to a class.
Understanding Classes and
Objects
Let’s have a more practical example
regarding classes and objects. Visual
Basic .NET treats everything as an
object. From the strings and integer
data types to the actual button used in
the form, these are all known as
objects. Let’s look at the form control
button.
Output
Understanding the button as a
class element
BUTTON PROPERTIES
NAME btnRed btnOrange btnGreen
Text Button 1 Button 2 Button 3
Back Red Orange Green
Color/Custom

Font Size: 14 9 11
Font Style Bold: True False True
Font Style Italic False True True
The button’s methods are a series of
subroutines and functions within the
button class.

Below are just some common examples


for button methods:
Focus – sets the input focus to the button
Hide – hides the button from the form
Refresh – reloads the button on the form
Show – displays the button on the form
Creating a Custom Class
To create your own Visual Basic class, click
on New Project and select the Class Library
from the list of templates.

Refer to the code snippet that uses custom


methods for getting and storing variable
values found on the next page to see the
Class Library option in the Visual Basic .NET
project templates list.
After you give your class a name, a coding
window will load and this is where we begin
writing down the elements of our class.

A class is simply a template where we can create


specific objects.

The variables that are in the class can also be


seen as templates that objects can use.

A customer will definitely have a name, an


address, and a contact number.
Declaring class variables
Properties and Methods for
Custom Classes
Public Class Customer
Private CustomerName As String
Private CustomerAddress As String
Private CustomerContactNo As String
Public Sub SetName(ByVal Name As String)
CustomerName = Name
End Sub
Public Function GetName() As String
Return CustomerName
End Function
End Class
The Property Method
Public Property Name() As String
Get
Return CustomerName
End Get
Set(ByVal CName As String)
CustomerName = CName
End Set
End Property
It illustrates how to begin to declare the
Property Method. It needs an access
modifier and a data type. The default
syntax is as follows:

• Get block returns the value of the


property.
• Set block accepts the parameter and
stores that information as a new value.
Using Custom Class Libraries
Dim newCustomer As New
Customer()
newCustomer.Name = “Juan
dela Cruz”
newCustomer.Address = “Unit 1
Bayan Street, Quezon City Metro
Manila.”
newCustomer.ContactNo = “333-
4444”
MsgBox(“The newest customer
is ” & newCustomer.Name)
Lesson 8:
User Accessibility
Objectives:
In this lesson, the students will be able to:

1. Design a basic user interface.


2. Create various controls for your
application.
Message Box
It is a predefined dialog box that can
be used to display information for
the user or ask the user for simple
user information.
A Simple MessageBox
Syntax for MessageBox
MsgBox(Prompt, Style Value, Title)
Where:
• Prompt, displays the message we want to put in
the message box.
• Styles Values please refer to the table below.
• The last parameter is Title. Are you tired of
having “WindowsApplication1” appearing at the
head of your message box? We can change that
default.
Style Values for Message Box
Button Values
Example Output
Writing the Codes:
Public Class frmMessageBox
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim MsgBoxTest As Integer
MsgBoxTest = MsgBox("Has the button been clicked?",
MsgBoxStyle.YesNo + MsgBoxStyle.Exclamation, "Something happened")
If MsgBoxTest = 6 Then
lblMessage.Text = "That’s right you did click on a button!"
Else
lblMessage.Text = "You’re lying!"
End If
End Sub
End Class
Setting the Properties
Controls Property Setting
Form 1

Label 1

Button 1
Multiple Forms

Add a new form

To add another form to your project, simply


click on the Add New Item icon on the menu
and select Add Windows Form. The Add New
Item pop-up will appear. Select Windows Form
from the options and click Add. You can access
your new form using the tabs located in the
Windows Form Designer Window.
Working with Multiple Forms
Writing the Codes
Public Class frmOne
Dim Form2 As New frmTwo
Private Sub Button1_Click(ByVal Sender As
System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Form2.Show()
End Sub
End Class
Setting the Properties
Controls Property Setting
Form 1

Form 2

Label1

Label2

Button 1
Dialog Box
A dialog box is also
known as a modal form.
Unlike in modeless forms,
the user can no longer
interact with Form 1
unless it interacts with
Form 2 first, once a
modal form is called.
These forms are also
known as being able to
return a value back to the
form that called it.
Menu
Menus allow you to group commands in
your application by a common theme.
It also makes the user interface of your
application organized.
You can also provide access keys and
shortcut keys to make menu navigation
easier for the repeat users of your
application.
CREATING MENU
Choose MenuStrip on the toolbox as
shown below.
SETTING PROPERTIES
CONTROL PROPERTY SETTING
FORM1
FORM2
BUTTON1
FORM3
BUTTON1
FORM4
BUTON1
FORM5
BUTTON1
FORM6
BUTTON1
Writing the Codes
Private Sub
LESSON1ToolStripMenuItem_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles
LESSON1ToolStripMenuItem.Click
Form2.Show()
Me.Hide()
End Sub
Writing the Codes
Private Sub
EXITToolStripMenuItem_Click(ByVal sender
As System.Object, ByVal e As
System.EventArgs) Handles
EXITToolStripMenuItem.Click
End
End Sub
OUTPUT
Lesson 9:
Accessing Data
Objectives:
In this lesson, the students will be able to:

1. Use text files on VB.NET applications.


2. Create a basic database application in
VB.NET.
Using Text Files
A text file is a Windows file that has the
extension .txt. Windows programs like
Notepad normally generate these files.
We usually use them to write notes, but
did you know that text files can also be
used to store data that you can access
with your Visual Basic program?
Save your file in your
desktop as test.txt
Creating an Interface
Setting Properties
CONTROLS PROPERTY SETTING
FORM1 NAME
TEXT
LABEL1 NAME
TEXT
BUTTON1 NAME
TEXT
Opening and Reading a Text
File
Public Class Form7
Private Sub btnBrowse_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnBrowse.Click
Dim filename As String = "C:\Users\GIN-LAPTOP\Desktop\
test.txt"
Dim fileholder As New System.IO.StreamReader(filename)
lblTxtFile.Text = fileholder.ReadToEnd
fileholder.Close()
End Sub
End Class
Output
Common methods used for the StreamReader class
Manipulating Strings
We have created a very simple text file but most of
the time, when we process data from a text file, it
will not just have one word per line.
One of the most common files processed are
Comma Separated Value (CSV) files. As defined
in Wikipedia, a CSV file is “a simple text format for
a database table.
Each record in the table is one line of the text file.
Each field value of a record is separated from the
next by a character.” Based on this description, it’s
very easy to create a CSV file using Notepad.
OUTPUT
WRITING CODES
Dim ColorRed As String = “Apple, Tomato,
Cherry, Strawberry”
Dim i As Integer
Dim RedArray() As String
RedArray = ColorRed.Split(“,”)
For i = 0 To UBound(RedArray)
MsgBox(RedArray(i))
Next i
Writing to a Text File
The opposite operation of reading a file is
writing to a file and that method is also
available in Visual Basic .NET. Writing to a file is
important since we need to store the data that
our users input to our program. If we do not
write the data to a text file, after we close the
program all the data that the users have
inputted will be lost.
Creating an Interface
Writing Codes
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim filename As String = "C:\Users\GIN-LAPTOP\Desktop\test2.txt"
If System.IO.File.Exists(filename) = True Then
Dim fileholder As New System.IO.StreamWriter(filename)
fileholder.Write(txtboxUserInput.Text)
fileholder.Close()
MsgBox("Text written to file")
Else
MsgBox("File Does Not Exist")
End If
End Sub
End Class
Output
By adding True, you are telling StreamWriter that
you do not want a completely new file made but
rather you want to append to the file that you are
writing to. Other common methods available to
StreamWriter objects are as follows:
Using a Database
• Applications need to communicate with
a database for the following tasks:
• Retrieving data stored in the database
and presenting it in a user-friendly
format
• Updating the database (i.e., inserting,
modifying, and deleting data)
ADO.NET Model
ADO.NET is a model used by .NET applications to communicate with a dataset
for retrieving, accessing, and updating data.
• ADO.NET is designed to operate as a
disconnected recordset. That means ADO.NET
does not hold a connection to the database and
does not automatically send updates back to the
database.
• A disconnected database model is where your
application makes a connection to the database
long enough to take a snapshot of the data and
then disconnects. You then add, delete, and
modify the data cached locally on your PC. When
you’re ready, you reconnect to the database and
merge your locally cached changes back to the
original database.
Your application can access data from a
database in two ways:
• DataReader – an object which is a
component of the Data Provider, uses the
Connection object to connect to the
database and the Command object to
retrieve data. When using DataReader,
you need to have a prior knowledge of
SQL.
• DataSet – caches data in a DataSet then
the application accesses data from it.
Lesson 10:
Completing an
Application
Objectives:
In this lesson, the students will be able to:

1. Differentiate traditional approaches in


software development projects.
2. Identify the general steps in developing
a Visual Basic .Net application
Software Development Life
Cycle (SDLC)
Being a programmer or a software developer
isn’t all about writing programs. A lot of time
is dedicated to making sure that the
resources allocated to the development of
the software solution will be used efficiently.

The programmer is not a one-man army in


making software solutions and more often
than not, the programmer is part of a bigger
team that creates the overall software
solution
Three Types of SDLC
1. Waterfall Model - Software
development projects can be divided
into stages. Only after all work for that
stage of the project has been refined
and completed can the team proceed
to the next stage. The term “waterfall”
is thus derived since work “cascades”
from one stage to the other.
2. Spiral Model - While the waterfall
model finishes one stage before
proceeding to the next, the spiral
model overlaps one stage with
another in order to speed up
development. James R. Chapman
describes the Spiral Model as the
ultimate evolution from the waterfall.
3. Prototyping - Prototyping is building
a dummy system that is a replica of
what should be the final output of
your development team. SDLC can be
applied on the prototype by using the
waterfall or spiral models.
The Development Process
1. Create a Design Specification
2. Create the User Interface
3. Set Properties for the User Interface
Objects
4. Writing the Codes
5. Test and Debug Application
6. Make an Executable File
7. Create a Setup Application
Wrapping Up Your Program
• You need to be able to share your
application to other people and not just
run it in Visual Basic .NET debug mode.
There are two ways to do this:
By sharing the executable file of your
application or by creating a setup file or
installer for your application.
Wrapping Up Your Program
• The executable file of your application can
easily be located in the “…\bin\debug”
folder of your application. While it’s very
easy to simply give an executable file to the
user, a classier way of sharing an
application is by making an installer.
• To make an installer for your program,
simply click on the Projects option of the
Menu and select Publish msgbox.
The window for the Publishing Wizard will appear
The Publishing Wizard will have the
following steps:
• Specify where the setup file will be saved
after the publishing wizard is finished.
• Choose how the users will install your
application:
a. From a Website
b. From a UNC Path or File Share
c. From a CD-ROM or DVD-ROM
• For this step, the third option is normally
used for general applications.

• Choose where the program will check for


updates:
a. Specify the location of the updates.
b. Set the application to not check for
updates.
• For standalone programs, the option to
check for updates is normally disabled.
Other programs do have an option to
check for updates using the Internet.

After those steps, the Publishing Wizard will


create your program installer. When this
application is installed on the client
machine, a shortcut will be added to the
Start Menu, and the application can be
uninstalled via Add/Remove Programs.

You might also like