Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 13

Visual Basic .NET (VB.

NET)
 Is an object-oriented computer programming language that can be viewed as an evolution
of Microsoft's Visual Basic (VB) which is implemented on the Microsoft .NET Framework. Microsoft
currently supplies Visual Basic free of charge.

Microsoft .NET Framework


Is a software framework that can be installed on computers running Microsoft Windows operating
system.

Creating an Application using Visual Basic .NET


 When creating an application, we then first create a blank Visual Studio.NET solution, and then you
add one or more projects to the solution.

Solution
A solution is simply a container that stores the projects and files for an entire application.

Project
A project also is a container, but it stores files associated with only a specific piece of the
application.

 Although, the idea of solution, projects, and files may sound confusing, the concept of placing
things in containers is nothing new to you. Think of a solution as being similar to drawer in a filing
cabinet. A project then is similar to a file folder that you store in a drawer, and a file is similar to
a document that you store in the file folder. You can place many file folders in a filling cabinet
drawer, just as you can place many projects in a solution. You also can store many documents in
a file folder, similar to the way you can store many files in a project.

Illustration:

Project
Solution

Files
The Windows Form Designer Window
 Is where you create (or design) the user interface for your project. Recall that a user interface is what
you see and interact with when using an application.

Windows Form Object


A Windows Form object appears in the designer window. A Window Form object is the foundation
for the user interface in a Window-based application. You create the user interface by adding other
objects, such as buttons, text boxes, etc. to the form. Dots are displayed in the form to assist you in
aligning the objects. The dots will not be visible when you run the application.

The Solution Explorer Window


 The Solution Explorer window displays a list of the properties contained in the current solution, and
the items contained in each project.

The Properties Window


 As is everything is an object-oriented language, a form file is an object. Each object in Visual
Basic.NET has a set of characteristics, called properties, associated with it. The properties, which
determine an object’s appearance and behavior, are listed in the Properties window. When an object
is created, a default value is assigned to each of the properties.

Object Box and Properties list


The object box is located immediately below the Properties window’s title bar. The Object box
contains the name of the selected object. When an object is selected, its properties appear in the
Properties window. The Properties list, which can be displayed either alphabetically or by category,
has two columns. The left column display all the properties associated with the selected object. The
right column, called Setting box, display the current value, or setting, of each of the properties.

Toolbox Window
 Toolbox window, or toolbox, contains the tools and other components you use when designing
a user interface. The content of the toolbox vary depending on the designer in use.
 The toolbox contains five (5) tabs which are labeled:
i. Data
ii. Components
iii. Windows Forms
iv. Clipboard Ring
v. General.
Basic Tools Included in the Windows Forms Designer Toolbox.
Tool Name Purpose
Pointer Allows you to move and size forms and controls
Label Displays text that the user cannot edit during run
time.
LinkLabel Adds a Web style link to a Windows Forms
application
Button Displays a standard button that the user can click to
perform actions
TextBox Accepts and displays text that the user can edit
during run time.
MainMenu Displays a menu while an application is running
CheckBox Displays a box that indicates whether an option is
selected or deselected
RadioButton Displays a button that indicates whether an option is
selected or deselected.
GroupBox Provides a visual and functional container for
controls; similar to the Panel control, but can
display a caption but no scroll bars.
PictureBox Displays graphics in bitmap, GIF, JPEG, metafile,
or icon format.
Panel Provides a visual and functional container for
controls; similar to the GroupBox control, but can
display scroll bars but no caption
DataGrid Displays data in a series of rows and column
ListBox Displays a list from which a user can select one or
more items.
CheckedListBox Displays a scrollable list of items, each
accompanied by a check box
ComboBox Displays a drop-down list of items
ListView Displays items in one of four views (text only, text
with small icons, text with large icons, or report
view.
TreeView Displays a hierarchy of nodes that can be expanded
or collapsed.
TabControl Displays multiple tabs.
DateTimePicker Allows the user to select a single item from a list of
dates or times.
MonthCalendar Displays an intuitive graphical interface for users to
view and set date information
HScrollBar Displays a horizontal scroll bar
VScrollBar Displays a vertical scroll bar
Timer Performs actions at specified time intervals
Starting Visual Basic .NET
 Click <Start> <Program> <Microsoft Visual Basic .NET>

The Visual Basic .NET (Start Page window)

Server Explorer Window

Toolbox Window
Solution Explorer Window

Dynamic Help Window

Class View Window

Window Purpose
Class View Display the classes, methods, and properties included in a solution
Dynamic Help Display links to context-sensitive help
Server Explorer Display data connections and servers
Start Page Display the panes associated with the Start Page links
Toolbox Display items that you can use when creating a project.

To create a VB.NET Application:


 Click <File>
 Click <New>
 Click <Blank Solution>
The New Project Dialog Box

 Project Type: Visual Studio Solutions


 Templates: Blank Solution

To change the solution name (default name is Solution1) and Location (where to save your application)
 Go to Name text box and change Solution1 to required filename format
 Go to Location text box and click <Browse> button and select the required
location/directory/folder.
 Then, click <OK> button

The Solution Explorer with Solution1 (0) projects

To add new Visual Basic .NET project to the current solution:


 Right click Solution1 (0 projects)
 Click <Add>
 Click <New Project>

The Add New Project Dialog Box

 Project Type: Visual Basic Projects


 Templates: Windows Application

To change the project name (default name is WindowsApplication1) and Location (where to save your
application)
 Go to Name text box and change WindowsApplication1 to required filename format
 Go to Location text box and click <Browse> button and select the required
location/directory/folder.
 Then, click <OK> button
The Visual Basic .NET (design) – (screen display)

Project Name

Project Information

Properties Window

Windows Form Designer Window

View Code
Solution
View Designer
Project
Refresh
Form
Show All Files

Properties

Working with some controls (objects) and their properties:


Prefix Property Name Example
 Form frm frmFormName frmSample
 Label lbl lblLabelName lblSample
 TextBox txt txtTextboxName txtSample
 Button btn btnButtonName btnSample

Note:
 Change only those object property names if it is needed in your program codes.
 Changing object property name is a good practice in developing a Visual Basic .NET application
Name : _______________________ Date Finished: ________ Rating:
Course/Section: _________ Time: ________
Instructor : _______________________

PRACTICE EXERCISE #1:

Sample Interface/Form layout: Edited Form:

Changing the properties of some controls/objects

Objects/Controls Name Text Event/Procedure


Form1 frmSample Sample Application Load
Label1 Label1 Enter your name: None
Label2 lblWelcome Welcome to Visual Basic .NET None
TextBox1 txtName None None
Button1 btnClick Click Click

Sample Output:

Writing Codes to your Form (Sample Application)


 Double click the <Click> button
 Type the code below:
o btnClick_Click procedure/event
 Double click the <Form>
 Type the code below:
o frmSample_Load procedure/event

To run the application:


 Press <F5> function key OR
 Click <Start> button
Public Class frmSample
Inherits System.Windows.Forms.Form

Private Sub btnClick_Click(ByVal sender As System.Object, ByVal e


As System.EventArgs) Handles btnClick.Click
lblWelcome.Text = "Welcome! " & txtName.Text
End Sub

Private Sub frmSample_Load(ByVal sender As System.Object, ByVal e


As System.EventArgs) Handles MyBase.Load
txtName.Text = "Richard Gwapo"
End Sub
End Class

The Code Window:

Class Name Method Name

Notes:
 In writing program codes / event procedure codes you can click the <View Code> button under
Solution Explorer window.
 All procedure/event procedure will be generated between the Public Class and End Class
keyword.
 Select the class name and the method name.
 Procedure/Event Procedure name will depend on defined object property name.
 Object Procedure/Event Procedure name and argument lists will be automatically displayed once
the object is being selected for code/program implementation.
 Type the line of statement(s) between the Private Sub and End Sub keyword
o Single statement per line.
o Use underscore ( _ ) to continue on the next line.
 Use single quotation symbol ( ‘ ) if you wish to include comments.
 Use & or + symbol to concatenate string values.
 Visual Basic .NET codes use color coding:
o Green – for comments
o Blue – for keywords / reserved words
o Black – for property name, string, variables & etc.
 Code with underline (color blue underline) means wrong:
o object name
o usage of property
o undefined variable
o etc.
 Switching from Code Window to Form Window OR vice versa click <View Code> button and
<View Designer> button under Solution Explorer Window
 During run time you can go back to your form window by closing the running application (click
<Close> button) OR click <Stop Debugging> button
 Try to use other object property for some enhancements of your form.
 In changing object property be sure to select the desired object before applying any properties
attached to that object. (Click once the object)
Name : _______________________ Date Finished: ________ Rating:
Course/Section: _________ Time: ________
Instructor : _______________________

PRACTICE EXERCISE #2:

 Use the same Solution and Project and add new form (Form2) to your project:

Sample Interface / Form Layout:

Instructions:
 Add five labels objects/controls to your form
 Change the object name:
o lblBlue
o lblGreen
o lblYellow
o lblRed
o lblWhite
 Type the codes below using the MouseMove
Method for each object.

Source codes:
Public Class frmColor
Inherits System.Windows.Forms.Form

Private Sub lblBlue_MouseMove(ByVal sender As Object, ByVal e As


System.Windows.Forms.MouseEventArgs) Handles
lblBlue.MouseMove
Me.BackColor = Color.Blue
End Sub

Private Sub lblGreen_MouseMove(ByVal sender As Object, ByVal e As


System.Windows.Forms.MouseEventArgs) Handles
lblGreen.MouseMove
Me.BackColor = Color.Green
End Sub

Private Sub lblRed_MouseMove(ByVal sender As Object, ByVal e As


System.Windows.Forms.MouseEventArgs) Handles
lblRed.MouseMove
Me.BackColor = Color.Red
End Sub

Private Sub lblWhite_MouseMove(ByVal sender As Object, ByVal e As


System.Windows.Forms.MouseEventArgs) Handles
lblWhite.MouseMove
Me.BackColor = Color.White
End Sub
Private Sub lblYellow_MouseMove(ByVal sender As Object, ByVal e
As System.Windows.Forms.MouseEventArgs) Handles
lblYellow.MouseMove
Me.BackColor = Color.Yellow
End Sub
End Class

Operators in Visual Basic .NET


In order to compute inputs from users and to generate results, we need to use various mathematical
operators. In Visual Basic, except for + and -, the symbols for the operators are different from normal
mathematical operators.

Arithmetic Operators:
Operator Mathematical function Example
^ Exponential 2^4=16
* Multiplication 4*3=12
/ Division 12/4=3
Mod Modulus(return the remainder 15 Mod 4=3
from an integer division)
\ Integer Division(discards the 19\4=4
decimal places)
+ or & String concatenation "Visual"&"Basic"="VisualBasic"

You might also like