عرض مقدمة البرمجة الشيئية

advertisement
Distance Learning Center
Lecture 1
Introduction to Visual Basic
Programming
January 10, 2005
LectureniL .M -1
1
Lecture 1: Introduction

Introduction – Learning objectives of the
class

Installation of Visual Studio .NET2005

Introduction to Visual Basic .NET2005
• Basic Concept of Visual Basic
Programming Language
• Programming Environment

January 10, 2005
Use Microsoft Visual Studio .NET2005
LectureniL .M -1
2
January 10, 2005
LectureniL .M -1
3
Learning Objectives





Visual program design and development
Fundamentals of Object Oriented
Programming (OOP)
Event driven programming
Objects, properties and methods
Write Visual Basic projects
Windows History: Windows 1.0
January 10, 2005
LectureniL .M -1
4
Text Book & References


Text book:
• Programming in Visual Basic .NET – 2005
Update Edition by Julia Case Bradley and Anita
C. Millspaugh, McGraw-Hill, ISBN 0-07-297039-1
References:
• Online Learning Center:
http://www.mhhe.com/vbnet2005
• Microsoft VB.NET Homepage:
http://www.microsoft.com/net
• VB developers Resource Center:
http://www.mvps.org/vbnet
• Microsoft Developers Network Homepage for
VB.NET: http://msdn.microsoft.com/vbasic
• Paul D. Sheriff, PDSA, Inc.
A Web Introduction to VS.NET
• MSDN Home page
http://msdn.microsoft.com/
January 10, 2005
LectureniL .M -1
5
Installing Microsoft Visual
Studio .NET 2005
1.
System requirements
Microsoft VS.NET System Requirements Page
2.
Install the Microsoft Visual Studio .NET
framework
•
3.
Insert the Microsoft Visual Studio .NET CD
•
•
•
4.
January 10, 2005
This is one of the Windows XP updates, listed as
“recommended”
Approximately 2 GBytes of disk space is used
Help files (MSDN) are valuable
Can also install C++ & C# if desired
Follow items 1, 2, and 3 on the setup screen
to complete your installation
LectureniL .M -1
6
Overview of Programming
The Structure and Operation of a Computer
 Computer system: hardware and software
 Processor (registers, primitive operations)
 Main memory (RAM, ROM)
 Data types (integers, real, floating-point
numbers, strings, etc.)
 Sequence and Data Control
 Storage management
 Operating environment
Reference: Computer Functions and Applications, by P. Lin
http://www.etcs.ipfw.edu/~lin/Presentation/CompNetApps11_17_files/frame.htm
January 10, 2005
LectureniL .M -1
7
Overview of Programming
(continue)
Computer System (PC)
Hardware
Processor,
Memory
January 10, 2005
Software
Data types,
Sequence and
Data Control,
Storage Management,
Operating Environment
LectureniL .M -1
8
Major Components of
Computer Systems




January 10, 2005
Input Unit (keyboard, mouse,
scanner, Internet through TCP/IP)
Central Processing Unit (CPU)
Output Unit
Memory Unit
• Primary memory (RAM, ROM)
• Secondary memory (Hard drives,
zip disks, floppy disks, etc)
LectureniL .M -1
9
Object Technology



January 10, 2005
Objects are essentially reusable
software components that model items
in the real world, such as windows
cars, vehicles, and so on
Object technology is a packaging
scheme that enables programmers to
create meaningful software units.
Object-Oriented Programming tends
to produce software that is more
understandable, better organized, and
easier to maintain, modify and debug.
LectureniL .M -1
10
Object Model

Object ==> Noun
• Form and Controls

Property ==> Adjective
• Color of a Form

Method ==> Verb
• Move a Form

Event ==> Occurs when the user takes an action
• User clicks a button, User moves a form

Class ==> Template to create new object
• Each control added is an Instance of a Class
January 10, 2005
LectureniL .M -1
11
Dot Notation

Used to reference object's properties and
events in code
• Object dot Property

Form.Text, TextBox.Text
• Object dot Event


Form.Hide( ), TextBox.Focus( )
To reference an object's events use an
underscore instead of a dot

January 10, 2005
Button_Click, ListBox_TextChanged
LectureniL .M -1
12
Object Model Analogy





Class = automobile
Properties = make, model, color, year
Object = each individual car
• Object is also an Instance of the automobile
class
Methods = start, stop, speedup, slowdown
Events = car arrives, car crashes
January 10, 2005
LectureniL .M -1
13
Visual Basic .NET Programming

Learning Visual Basic.NET Programming
Language includes to learn:
• The graphical user interface or GUI
(“gooey”) which is an essential
component of visual programming

The GUI defines how various elements
look and function
• Visual Basic programming language
Microsoft Developers Network Homepage for
VB.NET: http://msdn.microsoft.com/vbasic
January 10, 2005
LectureniL .M -1
14
A Sample Graphical User
Interface (GUI)
TextBox
Label
GroupBox
PictureBox
RadioButtons
Buttons
Form
January 10, 2005
LectureniL .M -1
15
VB.NET Program Development

To create a VB.NET program you will utilize
the Visual Basic .NET 2005 development
environment, and you will
• create a window, called form
• select elements, which are classes, from a
toolbox and place them within the window,
called controls
• write code for each object that you place
on the window that defines how the object
responds to various events, called objectoriented programming (OOP).
January 10, 2005
LectureniL .M -1
16
Event-Driven Programming

The style of Execution as shown below is
called event-driven:
• A GUI determines how a user interacts with
the program
• Each user interaction with the computer:
pressing a key, clicking a button, or selecting
a menu item causes an event to occur
• Whenever an event occurs, the code you
have written to handle that event is executed
January 10, 2005
LectureniL .M -1
17
VB.NET Object Oriented
Programming


Using the VB.NET OOP Technology to work
with objects and develop an event-driven
program.
Each object consists of:
• Classes: Forms, Labels, Buttons, etc
• Objects: A particular Form, Label, Button, etc.
• Properties (attributes of an object): The Name
of a form, the Text in a Label, etc.
• Methods (the actions that an object performs
in response to GUI events): Close, Show,
Clear, etc.
• Event: when a user takes an action
January 10, 2005
LectureniL .M -1
18
About Visual Studio .NET
Framework

Visual Studio .NET 2005 includes:
• Visual Basic, Visual C++, C#, J#, and the .NET
framework.
• The .NET framework allowing objects from
different languages to operate together
• The .NET languages-based programs all compile
to a common machine language, called
Microsoft Intermediate Language (MSIL)
• The MSIL code runs in the Common Language
Runtime (CLR), which is part of the file .NET
framework.
January 10, 2005
LectureniL .M -1
19
About Visual Basic .NET
Framework


Visual Basic .NET 2005 provide:
• Object-Oriented Programming (OOP) solutions
and with increased object-oriented capabilities
• allowing for easier development of Web-based
applications
• interoperability with other languages
Major changes (to VB . NET) have been made, both
to the language syntax and the way that data are
stored and referenced
January 10, 2005
LectureniL .M -1
20
VB.NET Program
Development Process


Planning (design)
• design the GUI (user interface)
• list the objects and properties needed
• plan the event procedures (what the code does)
Programming (implementation)
• define the GUI using objects (Forms, Text Boxes,
Labels, etc.
• set the properties
• write BASIC code to implement procedures
January 10, 2005
LectureniL .M -1
21
VB.NET Application Files

Each Visual Basic application create the following
files with extensions:
• .sln - a solution file that holds information about
the project. This is the only file that is opened
• .suo - a solution user options file that stores
information about the selected options
• .vb - a .vb file that holds the definition of a form
• .resx - a resource file for the form
• .vbproj - a project file that describes the project
and lists the files are included
• .vbproj.user - a project user option file that
holds project option settings
January 10, 2005
LectureniL .M -1
22
Using Microsoft Visual Studio .NET




Click on ->
Start
Choose ->
All
Programs
Choose ->
Microsoft
Visual
Studio .NET
2005
Click on ->
Microsoft
Visual
Studio .NET
2005
January 10, 2005
LectureniL .M -1
23
Using Microsoft Visual Studio .NET
(continue)
• Click on> File
• Choose> New
• Select->
Project
January 10, 2005
LectureniL .M -1
24
Using Microsoft Visual Studio .NET
(continue)




Select ->
Visual
Basic
Projects
Select ->
Window
Application
Give a
Project
Name
Specify the
appropriate
location
January 10, 2005
LectureniL .M -1
25
Using Microsoft Visual Studio .NET
(continue)
The Microsoft VS Development
Environment is also called integrated
development environment (IDE):
• A form designer
• A code editor
• A compiler
• A debugger
• An object browser
• A Help facility
January 10, 2005
LectureniL .M -1
26
Using Microsoft Visual Studio .NET
(continue)



Each window can be moved, resized,
opened, closed, or customized
Menu bar
Toolbar
Menu bar
Toolbar
January 10, 2005
LectureniL .M -1
27
VB.NET – IDE Main Window
Tool bar
Menu bar
Tabs
Toolbox
Form
window
Solution
Explorer
window
Properties window
January 10, 2005
LectureniL .M -1
28
Toolbox


Click
Toolbox
from the
Toolbars
Toolbox
contains
a list of
tools that
helps to
design
projects
January 10, 2005
LectureniL .M -1
29
Solution Explorer
welcome.sln

View Code
Tool bar

View
Design/
Form

Properties
January 10, 2005
LectureniL .M -1
30
Properties
January 10, 2005
LectureniL .M -1
31
Remark Statement




Also known as Comment, used for
documentation
Non-executable
Automatically colored Green in Editor
Begins with an apostrophe ( ' )
• On a separate line from executable code
• At the right end of a line of executable
code
' Display the Hello World message.
January 10, 2005
LectureniL .M -1
32
Option Strict On
January 10, 2005
LectureniL .M -1
33
Visual Studio Help
Extensive Help feature includes
 Microsoft Developer Network library (MSDN)
 Entire reference manual
 Coding examples
 Filter MSDN help to display VB topics only
 Run MSDN from hard drive, CD or Web
 To view Help choose Contents, Index or
Search from Help Menu
 Context-Sensitive Help is available by
pressing F1
January 10, 2005
LectureniL .M -1
34
Help Menu
January 10, 2005
LectureniL .M -1
35
Help Menu
(continued)
• Select an
appropriate
subject
January 10, 2005
LectureniL .M -1
36
Summary

Introduction – Learning Objectives of the
class

Installation of Visual Studio .NET2005

Introduction to Visual Basic .NET2005
• Basic Concept of Visual Basic
• Visual Basic Programming Language

Use Microsoft Visual Studio .NET2005

Next - First Visual Basic Planning and
Programming
January 10, 2005
LectureniL .M -1
37
Question?
Answers
linm@ipfw.edu
January 10, 2005
LectureniL .M -1
38
Download