chapter two introduction to visual basic © prepared by: razif razali 1
TRANSCRIPT
CHAPTER TWOCHAPTER TWO
INTRODUCTION TO VISUAL BASIC
© Prepared By:Razif Razali 1
INTRODUCTIONINTRODUCTION
Visual Basic is an extremely flexible programming product designed for a variety of applications.
Students, managers, and people in various technical fields use Visual Basic to learn how to write practical, Windows-based programs; business professionals use Visual Basic to write macros that leverage the documents and capabilities of their Microsoft Office applications; and experienced software developers use Visual Basic to build powerful commercial applications and corporate productivity tools.
© Prepared By:Razif Razali
2
OBJECTIVESOBJECTIVES
In this chapter, you'll learn how to:Explore and configure the Visual Basic
development environment.Build your first program.
© Prepared By:Razif Razali
3
Why Visual Basic?Why Visual Basic?
The advantages of Visual Basic: It's simple language. Because Visual Basic is so popular, There are
many good resources (Books, Web sites, News groups and more) that can help you learn the language.
You can find many tools (Sharewares and Freeware) on the internet that will Spare you some programming time.
Compare to other languages, Visual Basic have the widest variety of tools that you can download on the internet and use in your programs.
Why Visual Basic?Why Visual Basic?
The disadvantages of Visual Basic:Visual Basic is powerful language,
but it's not suit for programming really sophisticated games.
It's much more slower than other languages.
© Prepared By:Razif Razali
5
VISUAL BASIC ENVIRONMENTVISUAL BASIC ENVIRONMENT
The Visual Basic development environment contains these programming tools and windows, with which you construct your Visual Basic programs: Menu barToolbarsVisual Basic toolboxForm windowProperties windowProject ExplorerImmediate windowForm Layout window
© Prepared By:Razif Razali
6
Graphical User InterfaceGraphical User Interface
Visual Basic allows you to create GUIsGraphic User Interface (GUI) comprises
◦Forms◦Controls◦Event-driven programming
Revolutionized the Computer IndustryAllows input forms or boxes…much
friendlier interface
Visual Basic GUI - ExampleVisual Basic GUI - Example
Text boxes
Frame
Labels
Option buttons
Check boxesCommand buttonsImage
Picture box
Graphic User InterfaceGraphic User Interface
Controls: The responsive objects a programmer places on a window
These objects recognize user actions such as mouse movements and button clicks
A good analogy: For Example◦Objects (nouns) Option button ◦Properties (adjectives) What it looks
like◦Methods (verbs) What it does
Writing Visual Basic ProjectsWriting Visual Basic Projects
The three-step process for planning projects◦Design the user interface
Sketch the screens with forms and controls needed
◦Establish the objects' properties Write down the properties for each object
◦Plan the Basic code Write out pseudo code for actions your program will
perform
When the Program is RunningWhen the Program is Running
Visual Basic monitors the controls in the window to detect any event (click, for example)
When events detected, examine program to see if there’s a procedure associated with it
If there is a procedure, execute itIf there is no procedure, wait for the next
event
The Visual Basic EnvironmentThe Visual Basic Environment
Form, Project Explorer, Properties, and Form Layout Windows
ToolboxMain Visual Basic windowToolbar, Form location & size informationHelpDesign- , Run- …
VB EnvironmentVB Environment
VB EnvironmentVB Environment
VB EnvironmentVB Environment
VB EnvironmentVB Environment
VB EnvironmentVB Environment
VB EnvironmentVB Environment
ControlControl
A control is a tool you use to create objects on a Visual Basic form.
You select controls from the toolbox and use the mouse to draw objects on a form.
You use most controls to create user interface elements, such as command buttons, image boxes, and list boxes.
© Prepared By:Razif Razali
19
ObjectObject
An object is a type of user interface element you create on a Visual Basic form by using a toolbox control.
You can move, resize, and customize objects by setting object properties.
Objects also have what is known as inherent functionality — they know how to operate and can respond to certain situations on their own.
A list box “knows” how to scroll, for example. You can customize Visual Basic objects by using event
procedures that are fine-tuned for different conditions in a program
© Prepared By:Razif Razali
20
PropertyProperty
A property is a value or characteristic held by a Visual Basic object, such as Caption or Fore Color.
Properties can be set at design time by using the Properties window or at run time by using statements in the program code.
In code, the format for setting a property is:Object. Property = Value
Where◦ Object is the name of the object you’re customizing.◦ Property is the characteristic you want to change.◦ Value is the new property setting.
For example,Command1.Caption = "Hello"
Could be used in the program code to set the Caption property of the Command1 object to “Hello”.
© Prepared By:Razif Razali
21
Event ProcedureEvent Procedure
An event procedure is a block of code that runs when a program object is manipulated.
For example, clicking the first command button in a program executes the Command1_Click event procedure.
Event procedures typically evaluate and set properties and use other program statements to perform the work of the program.
© Prepared By:Razif Razali
22
MethodMethod
A method is a special keyword that performs an action or a service for a particular program object.
In code, the format for using a method isObject. Method Value
Where◦ Object is the name of the object you are working with.◦ Method is the action you want the object to perform.◦ Value is an optional argument to be used by the
method.For example, this statement uses the Add Item method
to put the word Check in the List1 list box:List1.AddItem "Check"
© Prepared By:Razif Razali
23
NAMING VISUAL BASIC OBJECTSNAMING VISUAL BASIC OBJECTS
Programmers typically create names for their objects that clearly identify the purpose of the object and the toolbox control that created it.
For example, you might give the name lblInstructions to a label that displays user-operating instructions.
In this case, lbl stands for the Label control, and Instructions describes the label's purpose.
© Prepared By:Razif Razali
24
OBJECT NAMING CONVENTIONSOBJECT NAMING CONVENTIONS
© Prepared By:Razif Razali
25
Version of Visual BasicVersion of Visual Basic
Can be grouped into:-◦Learning Edition◦Professional Edition◦Enterprise Edition
Learning EditionLearning Edition
Basic programming editorHelps educate all users on how to
program in Visual Basic.
Professional EditionProfessional Edition
Includes new features such as Visual C++ 6.0 optimized native-code compiler, ADO (Active Data Object), Database Tools, Automatic Data Binding, Dynamic HTML, Mobile Computing, etc
Enterprise EditionEnterprise Edition
Visual Basic 6.0 Enterprise Edition includes step by step instructions for how to take advantage of Windows 2000 features, native code compiler, ADO (Active X Data Objects), Integrated Enterprise tools to implement databases into applications, Automatic data binding, Dynamic HTML Page Designer, Mobile Computing Support, Microsoft SQL Server 6.5 Developer Edition, Visual Modeler, Microsoft Visual SourceSafe 6.0 and much more.
SUMMARYSUMMARYGraphical User Interface (GUI)Programming Languages:
◦Procedural◦Object Oriented◦Event Driven
Objects, Properties and MethodsVersion of Visual BasicThe three step process
© Prepared By:Razif Razali
30