SlideShare a Scribd company logo
1 of 27
Lecture 2:
Introduction to Visual Basic (VB)
Zeyad Al-Qady
Topics
•
•
•
•
•
•
•
•
•

1. What is VB?
2. What is Event-Driven?
3. What is Object-Orientation?
4. Objects used in VB
5. VB objects naming practice
6. Files in VB
7. OOED Programming process
8. VB statements
9. VB Help
What is VB?
• A windows-based system using objects
responding to events
• An objected-oriented event-driven
programming language
Event-Driven
• Procedural languages – run from start to finish
with no human intervention
– Basic, COBOL, FORTRAN, C

• Event driven languages - waits for an event to
occur before taking any action
• Example of event
– The press of a key on the keyboard
– Movement of the mouse
– The click of a mouse button

• Programming in Windows is usually termed
event-driven programming
Objects
• Reusable software components that model
items in the real world
– e.g. GPA calculator, Tax calculator

• They are self-contained modules that
combine data and program code which pass
strictly defined messages to one another
Encapsulation
• The capability of an object to hide its
internal workings from other objects.
• In VB, programmers does not need to know
what is going on inside the object, but only
need to know how to work with the object’s
properties and methods
– How many drivers are mechanics?
Object-Oriented Event-Driven
Programming (OOED)
• OOED uses objects in the program and runs
only after the Events occur
• OOED is easier to work with
• Users can combine multiple objects to
create new systems or extend existing ones
Starting VB from your computer
…
•
•
•
•
•
•

Toolbox [p. 27]
Project Window [p. 28] useful icons
Properties windows [p. 30]
How to Add Controls [p. 36]
How to Add Code [p. 39]
The toolbar icons [p. 43]
1st Project (ShowName)
• A Form
• Three Command Buttons
– Show Name
– Click Me
– Exit

• One Text Box
• One Label
Forms and Controls as Objects
• Forms and Controls are two kinds of
objects you may use in VB
• A form is a virtual blank space to design
the user interface for a VB application
• The tools that you use to construct the user
interface are controls
– E.g. command button and textbox etc.
VB objects naming practice:
•

Start the name with a standard object abbreviation
–

•
•

•

cmd = command button, txt = text box, frm = form.

Finish the name with a descriptive word of the
objects purpose
Spaces and special characters are not allowed in an
objects name. (E.g. cmdCancel)
Examples might be:
–
–

frmMain.BackColor = vbRed
txtState.Text = ""
Features of Objects
• The programmer can manipulate the object
through the use of three key object features:
– properties
– methods
– events
Object Properties
• A property is a named attribute of an object.
• Using an analogy to English grammar, if an object
is thought of as a noun, then a property may be
thought of as an adjective.
• Used to change the appearance of objects.
• An example of the relationship between objects
and properties using an everyday object:
– shirt.color = "Green“
– shirt.launder = "Clean“
Setting Values of Properties
• During design time, properties may be set
in the Properties Window.
– You are in “Design Time” when you are
designing the project and adding code

• Some properties may be set or modified
during run time.
– You are in “Run Time” when you click the VCR
Run icon
Object Methods
• A set of predefined activities that an object can carry out.
• The syntax for using an objects method is:
– object.method

• A method is a verb that can be carried out by the
object.
• For the various VB objects, there are usually
several methods already available.
• Or advanced programmers can create their own
methods.
Methods Example
• Real life example
– dog.eat
– dog.bark
– dog.run

• A Visual Basic example
– E.g. frmMain.hide
Object Event
• An action taken by the object when notified by a message
• Or, user actions taken on the object that provokes a
response from the object.
• Examples
– Soccer ball: kicking, throwing, holding etc.
– Cat: feeding, hitting, calling etc.
– mouse click, form load, or key press.

• VB example
Private Sub cmdsubmit_Click()
…
End Sub
Files in Visual Basic
• All projects in VB have a .vbp (project) file
and at least one .frm (form file) file.
• Always save .frm files first and then save
project files. Use File|Save or File|Save
as… commands for this purpose or click
Disk icon on toolbar.
• Projects with graphics also have .frx (binary
form) files. They are saved automatically.
• Module files have a .bas extension and are
pure code files.
Save files
Important!
Save early.
All three types can and should have
same names.
Eliminate prefix (eg.frm)
Add graphic
•
•
•
•

Retrieve your 1st project from your disk
Use image control
Select a graphic
Change the size of graphic
– Stretch property of image control

• Save the project
Save it
• Use your last name
• Eg. chen.frm, chen.vbp, chen.frx

• Create a folder in your disk composed
of your name
• Copy files to your folder
• Drag the folder to:
• W:appsclassesmist4600homework
Dchentestfile folder
OOED Programming Process
• A six step process for writing an OOED computer
program:
1. Define problem.
2. Create interface
3. Develop logic for action objects
4. Write and test code for action objects
5. Test overall project
6. Document project in writing
More Practice
(step 1 to 3 only)
1. Circle problem revisit
–
–
–

I: radius
P: calculate circumference, calculate area
O: radius, circumference, area

1. Payroll problem revisit
–
–
–

I: employee name, pay rate, and hours worked
P: calculate gross pay
O: gross pay
Comments
• To explain the purpose of a program, or a
statement, a comment statement is added
– For yourself and others

• Any statement beginning with an apostrophe or
REM is a comment
• Comments can be added to end of statements
using apostrophe
VB Statements
• A statement is a reserved word
• Statements are instructions that are built into the
Visual Basic language
• Some examples are:
End
Option Explicit
Private Sub
Dim
Visual Basic Help
• There are three types of Help:
– Help menu option
– context-sensitive help
– and Auto Help

• In VB 6, Help uses the familiar Internet
Explorer browser interface for the first two
types of help.
• You can seek help by selecting Contents,
Index, or Search from the Help menu item
Context-Sensitive and Auto
Help
• With context-sensitive help, pressing the
F1 key provides help on whatever item the
cursor is located.
• With Auto Help, VB tries to help you with
a code statement by providing:
– A list of items to complete the statement
– Info on the statement you have started
– Tips on the type of data you are working with

More Related Content

Viewers also liked

Looping statement in vb.net
Looping statement in vb.netLooping statement in vb.net
Looping statement in vb.net
ilakkiya
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
thinkphp
 

Viewers also liked (8)

Looping statement in vb.net
Looping statement in vb.netLooping statement in vb.net
Looping statement in vb.net
 
Pemrograman desktop
Pemrograman desktopPemrograman desktop
Pemrograman desktop
 
Materi Pemrograman Desktop
Materi Pemrograman DesktopMateri Pemrograman Desktop
Materi Pemrograman Desktop
 
Object Oriented Programming In .Net
Object Oriented Programming In .NetObject Oriented Programming In .Net
Object Oriented Programming In .Net
 
Teknik pemrograman sem 2
Teknik pemrograman sem 2Teknik pemrograman sem 2
Teknik pemrograman sem 2
 
Learning VB.NET Programming Concepts
Learning VB.NET Programming ConceptsLearning VB.NET Programming Concepts
Learning VB.NET Programming Concepts
 
Introduction to .net framework
Introduction to .net frameworkIntroduction to .net framework
Introduction to .net framework
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
 

Similar to Lec02

ASP.NET Session 3
ASP.NET Session 3ASP.NET Session 3
ASP.NET Session 3
Sisir Ghosh
 
Learn the java basic programming with example and syntaxchapter1-part-b.pptx
Learn the java basic programming with example and syntaxchapter1-part-b.pptxLearn the java basic programming with example and syntaxchapter1-part-b.pptx
Learn the java basic programming with example and syntaxchapter1-part-b.pptx
GaytriMate
 
Intro to javascript (5:2)
Intro to javascript (5:2)Intro to javascript (5:2)
Intro to javascript (5:2)
Thinkful
 
ASP.NET Session 4
ASP.NET Session 4ASP.NET Session 4
ASP.NET Session 4
Sisir Ghosh
 

Similar to Lec02 (20)

Ms visual-basic-6
Ms visual-basic-6Ms visual-basic-6
Ms visual-basic-6
 
ASP.NET Session 3
ASP.NET Session 3ASP.NET Session 3
ASP.NET Session 3
 
Introduction to Visual Basic 6.0
Introduction to Visual Basic 6.0Introduction to Visual Basic 6.0
Introduction to Visual Basic 6.0
 
Vb 6ch123
Vb 6ch123Vb 6ch123
Vb 6ch123
 
Lecture 1.pptx
Lecture 1.pptxLecture 1.pptx
Lecture 1.pptx
 
Csharp introduction
Csharp introductionCsharp introduction
Csharp introduction
 
SE-IT JAVA LAB OOP CONCEPT
SE-IT JAVA LAB OOP CONCEPTSE-IT JAVA LAB OOP CONCEPT
SE-IT JAVA LAB OOP CONCEPT
 
Semi Detailed Lesson Plan in Programming Languages
Semi Detailed Lesson Plan in Programming LanguagesSemi Detailed Lesson Plan in Programming Languages
Semi Detailed Lesson Plan in Programming Languages
 
Learn the java basic programming with example and syntaxchapter1-part-b.pptx
Learn the java basic programming with example and syntaxchapter1-part-b.pptxLearn the java basic programming with example and syntaxchapter1-part-b.pptx
Learn the java basic programming with example and syntaxchapter1-part-b.pptx
 
Intro to javascript (5:2)
Intro to javascript (5:2)Intro to javascript (5:2)
Intro to javascript (5:2)
 
Programming basics
Programming basicsProgramming basics
Programming basics
 
LECTURE 4 alpha.ppt
LECTURE 4 alpha.pptLECTURE 4 alpha.ppt
LECTURE 4 alpha.ppt
 
Object Oriented Programming I
Object Oriented Programming IObject Oriented Programming I
Object Oriented Programming I
 
ASP.NET Session 4
ASP.NET Session 4ASP.NET Session 4
ASP.NET Session 4
 
[OOP - Lec 01] Introduction to OOP
[OOP - Lec 01] Introduction to OOP[OOP - Lec 01] Introduction to OOP
[OOP - Lec 01] Introduction to OOP
 
object oriented programming examples
object oriented programming examplesobject oriented programming examples
object oriented programming examples
 
Programming using C++ - slides.pptx
Programming using C++ - slides.pptxProgramming using C++ - slides.pptx
Programming using C++ - slides.pptx
 
visualbasic.ppt
visualbasic.pptvisualbasic.ppt
visualbasic.ppt
 
C# Summer course - Lecture 1
C# Summer course - Lecture 1C# Summer course - Lecture 1
C# Summer course - Lecture 1
 
Intro to javascript (6:27)
Intro to javascript (6:27)Intro to javascript (6:27)
Intro to javascript (6:27)
 

Recently uploaded

Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 

Recently uploaded (20)

Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 

Lec02

  • 1. Lecture 2: Introduction to Visual Basic (VB) Zeyad Al-Qady
  • 2. Topics • • • • • • • • • 1. What is VB? 2. What is Event-Driven? 3. What is Object-Orientation? 4. Objects used in VB 5. VB objects naming practice 6. Files in VB 7. OOED Programming process 8. VB statements 9. VB Help
  • 3. What is VB? • A windows-based system using objects responding to events • An objected-oriented event-driven programming language
  • 4. Event-Driven • Procedural languages – run from start to finish with no human intervention – Basic, COBOL, FORTRAN, C • Event driven languages - waits for an event to occur before taking any action • Example of event – The press of a key on the keyboard – Movement of the mouse – The click of a mouse button • Programming in Windows is usually termed event-driven programming
  • 5. Objects • Reusable software components that model items in the real world – e.g. GPA calculator, Tax calculator • They are self-contained modules that combine data and program code which pass strictly defined messages to one another
  • 6. Encapsulation • The capability of an object to hide its internal workings from other objects. • In VB, programmers does not need to know what is going on inside the object, but only need to know how to work with the object’s properties and methods – How many drivers are mechanics?
  • 7. Object-Oriented Event-Driven Programming (OOED) • OOED uses objects in the program and runs only after the Events occur • OOED is easier to work with • Users can combine multiple objects to create new systems or extend existing ones
  • 8. Starting VB from your computer … • • • • • • Toolbox [p. 27] Project Window [p. 28] useful icons Properties windows [p. 30] How to Add Controls [p. 36] How to Add Code [p. 39] The toolbar icons [p. 43]
  • 9. 1st Project (ShowName) • A Form • Three Command Buttons – Show Name – Click Me – Exit • One Text Box • One Label
  • 10. Forms and Controls as Objects • Forms and Controls are two kinds of objects you may use in VB • A form is a virtual blank space to design the user interface for a VB application • The tools that you use to construct the user interface are controls – E.g. command button and textbox etc.
  • 11. VB objects naming practice: • Start the name with a standard object abbreviation – • • • cmd = command button, txt = text box, frm = form. Finish the name with a descriptive word of the objects purpose Spaces and special characters are not allowed in an objects name. (E.g. cmdCancel) Examples might be: – – frmMain.BackColor = vbRed txtState.Text = ""
  • 12. Features of Objects • The programmer can manipulate the object through the use of three key object features: – properties – methods – events
  • 13. Object Properties • A property is a named attribute of an object. • Using an analogy to English grammar, if an object is thought of as a noun, then a property may be thought of as an adjective. • Used to change the appearance of objects. • An example of the relationship between objects and properties using an everyday object: – shirt.color = "Green“ – shirt.launder = "Clean“
  • 14. Setting Values of Properties • During design time, properties may be set in the Properties Window. – You are in “Design Time” when you are designing the project and adding code • Some properties may be set or modified during run time. – You are in “Run Time” when you click the VCR Run icon
  • 15. Object Methods • A set of predefined activities that an object can carry out. • The syntax for using an objects method is: – object.method • A method is a verb that can be carried out by the object. • For the various VB objects, there are usually several methods already available. • Or advanced programmers can create their own methods.
  • 16. Methods Example • Real life example – dog.eat – dog.bark – dog.run • A Visual Basic example – E.g. frmMain.hide
  • 17. Object Event • An action taken by the object when notified by a message • Or, user actions taken on the object that provokes a response from the object. • Examples – Soccer ball: kicking, throwing, holding etc. – Cat: feeding, hitting, calling etc. – mouse click, form load, or key press. • VB example Private Sub cmdsubmit_Click() … End Sub
  • 18. Files in Visual Basic • All projects in VB have a .vbp (project) file and at least one .frm (form file) file. • Always save .frm files first and then save project files. Use File|Save or File|Save as… commands for this purpose or click Disk icon on toolbar. • Projects with graphics also have .frx (binary form) files. They are saved automatically. • Module files have a .bas extension and are pure code files.
  • 19. Save files Important! Save early. All three types can and should have same names. Eliminate prefix (eg.frm)
  • 20. Add graphic • • • • Retrieve your 1st project from your disk Use image control Select a graphic Change the size of graphic – Stretch property of image control • Save the project
  • 21. Save it • Use your last name • Eg. chen.frm, chen.vbp, chen.frx • Create a folder in your disk composed of your name • Copy files to your folder • Drag the folder to: • W:appsclassesmist4600homework Dchentestfile folder
  • 22. OOED Programming Process • A six step process for writing an OOED computer program: 1. Define problem. 2. Create interface 3. Develop logic for action objects 4. Write and test code for action objects 5. Test overall project 6. Document project in writing
  • 23. More Practice (step 1 to 3 only) 1. Circle problem revisit – – – I: radius P: calculate circumference, calculate area O: radius, circumference, area 1. Payroll problem revisit – – – I: employee name, pay rate, and hours worked P: calculate gross pay O: gross pay
  • 24. Comments • To explain the purpose of a program, or a statement, a comment statement is added – For yourself and others • Any statement beginning with an apostrophe or REM is a comment • Comments can be added to end of statements using apostrophe
  • 25. VB Statements • A statement is a reserved word • Statements are instructions that are built into the Visual Basic language • Some examples are: End Option Explicit Private Sub Dim
  • 26. Visual Basic Help • There are three types of Help: – Help menu option – context-sensitive help – and Auto Help • In VB 6, Help uses the familiar Internet Explorer browser interface for the first two types of help. • You can seek help by selecting Contents, Index, or Search from the Help menu item
  • 27. Context-Sensitive and Auto Help • With context-sensitive help, pressing the F1 key provides help on whatever item the cursor is located. • With Auto Help, VB tries to help you with a code statement by providing: – A list of items to complete the statement – Info on the statement you have started – Tips on the type of data you are working with

Editor's Notes

  1. We use dot (“.”) notation