SlideShare a Scribd company logo
VB.Net Introduction
RCCS 307
BY W. LACKTANO
.NET Framework
• .NET Framework class libraries: A large set
of classes that forms the basis for objects
that can be used programmatically.
– Programming in the .NET Framework means
making use of the classes exposed by the
Framework, building your own classes on top
of these and manipulating the resulting objects.
• Creating Internet applications and Windows
applications
Class and Object
• A class is a blueprint from which objects
are made. Every object created from a
class is an instance of the class.
• Properties and methods: An object’s
interface consists of properties and
methods. A property is an attribute
associated with an object, while a method is
an action that the object can carry out.
VB.NET is Object-Oriented
• Everything from the simplest data types
provided by VB to the complex windows is
a class.
– Ex:
• Dim iNum as Integer
• iNum=10
• Debug.WriteLine (“The number is: “ &
iNum.ToString)
Visual Studio .NET
• It is the development environment for creating
applications based on the .NET Framework.
• It supports VB, C#, and C++.
• Demo:
– Start page: MyProfile
– Starting project: Project types, name and location,
– Solutions and projects, renaming a project, property
page, AutoHide, Dock/Float
– Configure start up environment: Tools/Option
– View/Solution, View/Class, Project/Add Windows
Form, Project/Add New Item
– Form, Code view, File Properties and Object properties
Introduction to Visual Basic .Net
• Event-driven programming
– The interface for a VB program consists of one
or more forms, containing one or more controls
(screen objects).
– Form and control has a number of events that it
can respond to. Typical events include clicking
a mouse button, type a character on the
keyboard, changing a value, etc.
– Event procedure
Typical VB.Net Controls
• TextBox
• Label
• Button
• CheckBox
• RadioButton
• ListBox
• ComboBox
• PictureBox
Text Box
• Properties:
– AutoSize, BorderStyle, CauseValidation, Enabled,
Locked, Multiline, PasswordChar, ReadOnly,
ScrollBar, TabIndex, Text, Visible, etc.
• Properties can be set at the design time or at the
run time using codes.
• To refer to a property:
– ControlName.PropertyName
– Ex. TextBox1.Text
Typical VB.Net Programming
Tasks
• Creatin g the GUI elements that make up
the application’s user interface.
– Visualize the application.
– Make a list of the controls needed.
• Setting the properties of the GUI elements
• Writing procedures that respond to events
and perform other operations.
Demo
Num1
Num2
Sum =
Control properties
Event: Click, MouseMove, FormLoad, etc.
Event procedures
Sum:
textBox3.text=CStr(CDbl(textBox1.text)+CDbl(textBox2.text))
Or (CDbl(textBox1.text)+CDbl(textBox2.text)).toString
Challenge: How to draw a horizontal line?
VB Projects
• A VB project consists of several files. Visual
Studio .Net automatically creates a project folder
to keep all project files in the folder.
– Solution file
– Project file
– Form file
– Modules
– Class file
– Etc.
Configure VB Project
• Project property page
– General
– Build: Option Explicit
– Imports
• Debug
– Debug/Windows
Introductory VB Topics
• Declaring variables: Option Explicit
– DIM, PUBLIC, PRIVATE, STATIC, CONST
– Boolean, Integer, Long, Single, Double, Date,
String
– Ex: DIM dblIntRate As Double
– Ex: Dim X As Integer, Y As Single
– Ex: Dim A, B, C As String
– Ex: Dim X AS Integer = 25
– Ex: CONST Maximum As Integer = 100
Variable Declarations
• Dim variableName as DataType
• Variable naming rules:
– The first character must be a letter or an underscore
character.
– Use only letters, digits, and underscore.
– Cannot contain spaces or periods.
– No VB keywords
• Naming conventions:
– Descriptive
– Consistent lower and upper case characters.
• Ex. Camel casing: lowerUpper, employeeName
Control Naming Conventions
• The first three letters should be a lowercase prefix
that indicates the control’s type.
– frm, txt, lbl, btn.
• The first letter after the prefix should be
uppercase.
– txtSalary, lblMessage
• The part of the control name after the prefix
should describe the control’s purpose in the
application.
VB Data Types
• Boolean (True/False): 2 bytes
• Byte: Holds a whole number from 0 to 255.
• Char: single character
• Date: date and time, 8 bytes.
• Decimal: Real number up to 29 significant digits, 16 bytes
• Double: real, 8 bytes
• Single: real, 4 bytes
• Integer: 4 bytes (int32, uint32)
• Long: 8 bytes integer
• Short: 2 bytes integer
• String
• Object: Holds a reference of an object
Variable Declaration Examples
• Dim empName as String
• Declare multiple variables with one Dim:
– Dim empName, dependentName, empSSN as String
• Dim X As Integer, Y As Single
• Initiatialization
– Dim interestRate as Double = 0.0715
Variable Default Value
• Variables with a numeric data type: 0
• Boolean variables: False
• Date variables: 12:00:00 AM, January 1 of
the year 1.
• String variables: Nothing
Object Reference
• Declare object variales:
– Dim varName As Classname
– varName = New Classname()
– Or: Dim varName As New Classname()
• Dereferencing objects:
– varName = Nothing
Variable Scope
• Block-level scope: declared within a block of code
terminated by an end, loop or next statement.
– If city = “Rome” then
• Dim message as string = “the city is in Italy”
• MsgBox(message)
– End if
• Procedural-level scope: declared in a procedure
• Class-level, module-level scope: declared in a
class or module but outside any procedure with
either Dim or Private keyword.
• Project-level scope: a class or module variable
declared with the Public keyword.
Data Conversion
• Implicit conversion: When you assign a value of
one data type to a variable of another data type,
VB attempts to convert the value being assigned to
the data type of the variable if the OptionStrict is
set to Off.
• Explicit conversion:
– VB.Net Functions: CStr, Ccur, CDbl, Cint, CLng,
CSng, Cdate,Val, etc.
– .Net System.Convert
• Type class’s methods:
– toString
Date Data Type
• Variables of the Date data type can hold both a
date and a time. The smallest value is midnight
(00:00:00) of Jan 1 of the year 1. The largest
value is 11:59:59 PM of Dec. 31 of the year 9999.
• Date literals: A date literal may contain the date,
the time, or both, and must be enclosed in #
symbols:
– #1/30/2003#, #1/31/2003 2:10:00 PM#
– #6:30 PM#, #18:30:00#
• Date Literal Example:
– Dim startDate as dateTime
– startDate = #1/30/2003#
• Use the System.Convert.ToDateTime
function to convert a string to a date value:
– startDate = System.Convert.ToDateTime(“1/30/2003”)
– If date string is entered in a text box:
• startDate = System.Convert.ToDateTime(txtDate.text)
• Or startDate=Cdate(txtDate.text)
Arithmetic and String Operators
• +, -, *, /. , ^
• String Concatenation: &, +
• Compound operator:
: X= X+1 or X +=1
IF Statement
• IF condition THEN
statements
[ELSEIF condition-n THEN
[elseifstatements]
[ELSE
[elsestatements]]]
End If
Select Case Structure
• SELECT CASE testexpression
[CASE expressionlist-n
[Statements]
[CASE ELSE
[elsestatements]
END SELECT
Select Case Example
• SELECT CASE temperature
CASE <40
Text1.text=“cold”
CASE 40 to 60
Text1.text=“cool”
CASE 60 to 80
Text1.text=“warm”
CASE ELSE
Text1.text=“Hot”
End Select
Loop
• FOR index – start TO end [STEP step]
[statements]
[EXIT FOR]
NEXT index
DO [{WHILE| UNTIL} condition]
[statements]
[EXIT DO]
LOOP
Do While/Do Until
Private Sub Command1_Click()
Dim counter As Integer
counter = 0
Do While counter <= 5
Debug.Print counter
counter = counter + 1
Loop
Text1.Text = counter
End Sub
Private Sub Command2_Click()
Dim counter As Integer
counter = 0
Do Until counter > 5
Debug.Print counter
counter = counter + 1
Loop
Text1.Text = counter
End Sub
With … End With
With TextBox1
.Height = 250
.Width = 600
.Text = “Hello”
End With
Convenient shorthand to execute a series of
statements on a single object. Within the block,
the reference to the object is implicit and need
not be written.
Procedures
. Sub procedure:
Sub SubName(Arguments)
…
End Sub
– To call a sub procedure SUB1
• CALL SUB1(Argument1, Argument2, …)
Function
• Private Function tax(salary) As Double
• tax = salary * 0.1
• End Function
– Or
• Private Function tax(salary)
• Return salary * 0.1
• End Function
Call by Reference
Call by Value
• ByRef
– Default
– The address of the item is passed. Any changes
made to the passing variable are made to the
variable itself.
• ByVal
– Only the variable’s value is passed.
ByRef, ByVal example
Private Sub Command1_Click()
Dim myStr As String
myStr = TextBox1.Text
ChangeTextRef (myStr)
TextBox1.Text = myStr
End Sub
Private Sub ChangeTextRef(ByRef strInput As
String)
strInput = "New Text"
End Sub

More Related Content

PPT
Visual basic intoduction
PDF
I x scripting
PPTX
19csharp
PPTX
PPTX
Lecture 2
PPT
Visual basic 6.0
ODP
Getting started with typescript and angular 2
PPTX
Introduction to C ++.pptx
Visual basic intoduction
I x scripting
19csharp
Lecture 2
Visual basic 6.0
Getting started with typescript and angular 2
Introduction to C ++.pptx

Similar to Introduction to VB.Net By William Lacktano.ppt (20)

PDF
Intro to javascript (5:2)
PPT
PPTX
TypeScript: Basic Features and Compilation Guide
PPTX
C# 101: Intro to Programming with C#
PDF
Delphi L02 Controls P1
PPTX
Chap_________________1_Introduction.pptx
PPTX
CS4443 - Modern Programming Language - I Lecture (2)
PPT
Presentatiooooooooooon00000000000001.ppt
PDF
EKON 23 Code_review_checklist
PDF
Intro to javascript (6:27)
PPTX
PDF
Intro to javascript (6:19)
PDF
Getting started with CATIA V5 Macros
PPTX
SoftwareApplicationInTermsOFMatlabSimulation
PDF
Open travel 2-0_introduction_jan_2014_slideshare
PDF
OOP UNIT 1_removed ppt explaining object.pdf
PDF
Metrics ekon 14_2_kleiner
PPTX
UNIT-2 OOM.pptxUNIT-2 OOM.pptxUNIT-2 OOM.pptx
PPTX
Visual Basic Fundamentals
Intro to javascript (5:2)
TypeScript: Basic Features and Compilation Guide
C# 101: Intro to Programming with C#
Delphi L02 Controls P1
Chap_________________1_Introduction.pptx
CS4443 - Modern Programming Language - I Lecture (2)
Presentatiooooooooooon00000000000001.ppt
EKON 23 Code_review_checklist
Intro to javascript (6:27)
Intro to javascript (6:19)
Getting started with CATIA V5 Macros
SoftwareApplicationInTermsOFMatlabSimulation
Open travel 2-0_introduction_jan_2014_slideshare
OOP UNIT 1_removed ppt explaining object.pdf
Metrics ekon 14_2_kleiner
UNIT-2 OOM.pptxUNIT-2 OOM.pptxUNIT-2 OOM.pptx
Visual Basic Fundamentals
Ad

Recently uploaded (20)

PDF
AI in Product Development-omnex systems
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PPTX
Introduction to Artificial Intelligence
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PPTX
Online Work Permit System for Fast Permit Processing
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PPTX
Odoo POS Development Services by CandidRoot Solutions
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
Nekopoi APK 2025 free lastest update
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
Digital Strategies for Manufacturing Companies
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
medical staffing services at VALiNTRY
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
top salesforce developer skills in 2025.pdf
AI in Product Development-omnex systems
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Introduction to Artificial Intelligence
Navsoft: AI-Powered Business Solutions & Custom Software Development
Online Work Permit System for Fast Permit Processing
How Creative Agencies Leverage Project Management Software.pdf
Design an Analysis of Algorithms II-SECS-1021-03
VVF-Customer-Presentation2025-Ver1.9.pptx
Odoo POS Development Services by CandidRoot Solutions
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PTS Company Brochure 2025 (1).pdf.......
Nekopoi APK 2025 free lastest update
CHAPTER 2 - PM Management and IT Context
Wondershare Filmora 15 Crack With Activation Key [2025
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Digital Strategies for Manufacturing Companies
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
medical staffing services at VALiNTRY
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
top salesforce developer skills in 2025.pdf
Ad

Introduction to VB.Net By William Lacktano.ppt

  • 2. .NET Framework • .NET Framework class libraries: A large set of classes that forms the basis for objects that can be used programmatically. – Programming in the .NET Framework means making use of the classes exposed by the Framework, building your own classes on top of these and manipulating the resulting objects. • Creating Internet applications and Windows applications
  • 3. Class and Object • A class is a blueprint from which objects are made. Every object created from a class is an instance of the class. • Properties and methods: An object’s interface consists of properties and methods. A property is an attribute associated with an object, while a method is an action that the object can carry out.
  • 4. VB.NET is Object-Oriented • Everything from the simplest data types provided by VB to the complex windows is a class. – Ex: • Dim iNum as Integer • iNum=10 • Debug.WriteLine (“The number is: “ & iNum.ToString)
  • 5. Visual Studio .NET • It is the development environment for creating applications based on the .NET Framework. • It supports VB, C#, and C++. • Demo: – Start page: MyProfile – Starting project: Project types, name and location, – Solutions and projects, renaming a project, property page, AutoHide, Dock/Float – Configure start up environment: Tools/Option – View/Solution, View/Class, Project/Add Windows Form, Project/Add New Item – Form, Code view, File Properties and Object properties
  • 6. Introduction to Visual Basic .Net • Event-driven programming – The interface for a VB program consists of one or more forms, containing one or more controls (screen objects). – Form and control has a number of events that it can respond to. Typical events include clicking a mouse button, type a character on the keyboard, changing a value, etc. – Event procedure
  • 7. Typical VB.Net Controls • TextBox • Label • Button • CheckBox • RadioButton • ListBox • ComboBox • PictureBox
  • 8. Text Box • Properties: – AutoSize, BorderStyle, CauseValidation, Enabled, Locked, Multiline, PasswordChar, ReadOnly, ScrollBar, TabIndex, Text, Visible, etc. • Properties can be set at the design time or at the run time using codes. • To refer to a property: – ControlName.PropertyName – Ex. TextBox1.Text
  • 9. Typical VB.Net Programming Tasks • Creatin g the GUI elements that make up the application’s user interface. – Visualize the application. – Make a list of the controls needed. • Setting the properties of the GUI elements • Writing procedures that respond to events and perform other operations.
  • 10. Demo Num1 Num2 Sum = Control properties Event: Click, MouseMove, FormLoad, etc. Event procedures Sum: textBox3.text=CStr(CDbl(textBox1.text)+CDbl(textBox2.text)) Or (CDbl(textBox1.text)+CDbl(textBox2.text)).toString Challenge: How to draw a horizontal line?
  • 11. VB Projects • A VB project consists of several files. Visual Studio .Net automatically creates a project folder to keep all project files in the folder. – Solution file – Project file – Form file – Modules – Class file – Etc.
  • 12. Configure VB Project • Project property page – General – Build: Option Explicit – Imports • Debug – Debug/Windows
  • 13. Introductory VB Topics • Declaring variables: Option Explicit – DIM, PUBLIC, PRIVATE, STATIC, CONST – Boolean, Integer, Long, Single, Double, Date, String – Ex: DIM dblIntRate As Double – Ex: Dim X As Integer, Y As Single – Ex: Dim A, B, C As String – Ex: Dim X AS Integer = 25 – Ex: CONST Maximum As Integer = 100
  • 14. Variable Declarations • Dim variableName as DataType • Variable naming rules: – The first character must be a letter or an underscore character. – Use only letters, digits, and underscore. – Cannot contain spaces or periods. – No VB keywords • Naming conventions: – Descriptive – Consistent lower and upper case characters. • Ex. Camel casing: lowerUpper, employeeName
  • 15. Control Naming Conventions • The first three letters should be a lowercase prefix that indicates the control’s type. – frm, txt, lbl, btn. • The first letter after the prefix should be uppercase. – txtSalary, lblMessage • The part of the control name after the prefix should describe the control’s purpose in the application.
  • 16. VB Data Types • Boolean (True/False): 2 bytes • Byte: Holds a whole number from 0 to 255. • Char: single character • Date: date and time, 8 bytes. • Decimal: Real number up to 29 significant digits, 16 bytes • Double: real, 8 bytes • Single: real, 4 bytes • Integer: 4 bytes (int32, uint32) • Long: 8 bytes integer • Short: 2 bytes integer • String • Object: Holds a reference of an object
  • 17. Variable Declaration Examples • Dim empName as String • Declare multiple variables with one Dim: – Dim empName, dependentName, empSSN as String • Dim X As Integer, Y As Single • Initiatialization – Dim interestRate as Double = 0.0715
  • 18. Variable Default Value • Variables with a numeric data type: 0 • Boolean variables: False • Date variables: 12:00:00 AM, January 1 of the year 1. • String variables: Nothing
  • 19. Object Reference • Declare object variales: – Dim varName As Classname – varName = New Classname() – Or: Dim varName As New Classname() • Dereferencing objects: – varName = Nothing
  • 20. Variable Scope • Block-level scope: declared within a block of code terminated by an end, loop or next statement. – If city = “Rome” then • Dim message as string = “the city is in Italy” • MsgBox(message) – End if • Procedural-level scope: declared in a procedure • Class-level, module-level scope: declared in a class or module but outside any procedure with either Dim or Private keyword. • Project-level scope: a class or module variable declared with the Public keyword.
  • 21. Data Conversion • Implicit conversion: When you assign a value of one data type to a variable of another data type, VB attempts to convert the value being assigned to the data type of the variable if the OptionStrict is set to Off. • Explicit conversion: – VB.Net Functions: CStr, Ccur, CDbl, Cint, CLng, CSng, Cdate,Val, etc. – .Net System.Convert • Type class’s methods: – toString
  • 22. Date Data Type • Variables of the Date data type can hold both a date and a time. The smallest value is midnight (00:00:00) of Jan 1 of the year 1. The largest value is 11:59:59 PM of Dec. 31 of the year 9999. • Date literals: A date literal may contain the date, the time, or both, and must be enclosed in # symbols: – #1/30/2003#, #1/31/2003 2:10:00 PM# – #6:30 PM#, #18:30:00#
  • 23. • Date Literal Example: – Dim startDate as dateTime – startDate = #1/30/2003# • Use the System.Convert.ToDateTime function to convert a string to a date value: – startDate = System.Convert.ToDateTime(“1/30/2003”) – If date string is entered in a text box: • startDate = System.Convert.ToDateTime(txtDate.text) • Or startDate=Cdate(txtDate.text)
  • 24. Arithmetic and String Operators • +, -, *, /. , ^ • String Concatenation: &, + • Compound operator: : X= X+1 or X +=1
  • 25. IF Statement • IF condition THEN statements [ELSEIF condition-n THEN [elseifstatements] [ELSE [elsestatements]]] End If
  • 26. Select Case Structure • SELECT CASE testexpression [CASE expressionlist-n [Statements] [CASE ELSE [elsestatements] END SELECT
  • 27. Select Case Example • SELECT CASE temperature CASE <40 Text1.text=“cold” CASE 40 to 60 Text1.text=“cool” CASE 60 to 80 Text1.text=“warm” CASE ELSE Text1.text=“Hot” End Select
  • 28. Loop • FOR index – start TO end [STEP step] [statements] [EXIT FOR] NEXT index DO [{WHILE| UNTIL} condition] [statements] [EXIT DO] LOOP
  • 29. Do While/Do Until Private Sub Command1_Click() Dim counter As Integer counter = 0 Do While counter <= 5 Debug.Print counter counter = counter + 1 Loop Text1.Text = counter End Sub Private Sub Command2_Click() Dim counter As Integer counter = 0 Do Until counter > 5 Debug.Print counter counter = counter + 1 Loop Text1.Text = counter End Sub
  • 30. With … End With With TextBox1 .Height = 250 .Width = 600 .Text = “Hello” End With Convenient shorthand to execute a series of statements on a single object. Within the block, the reference to the object is implicit and need not be written.
  • 31. Procedures . Sub procedure: Sub SubName(Arguments) … End Sub – To call a sub procedure SUB1 • CALL SUB1(Argument1, Argument2, …)
  • 32. Function • Private Function tax(salary) As Double • tax = salary * 0.1 • End Function – Or • Private Function tax(salary) • Return salary * 0.1 • End Function
  • 33. Call by Reference Call by Value • ByRef – Default – The address of the item is passed. Any changes made to the passing variable are made to the variable itself. • ByVal – Only the variable’s value is passed.
  • 34. ByRef, ByVal example Private Sub Command1_Click() Dim myStr As String myStr = TextBox1.Text ChangeTextRef (myStr) TextBox1.Text = myStr End Sub Private Sub ChangeTextRef(ByRef strInput As String) strInput = "New Text" End Sub