Pertemuan 02 Visual Basic Environment and Control Matakuliah

advertisement
Matakuliah
Tahun
Versi
: D0524 / Algoritma dan Pemrograman Komputer
: 2005
:
Pertemuan 02
Visual Basic Environment and Control
1
Learning Outcomes
Pada akhir pertemuan ini, diharapkan mahasiswa
akan mampu :
• Menjelaskan lingkungan dan kontrol pada Visual
Basic
2
Outline Materi
•
•
•
•
•
•
•
•
•
Why Visual Basic
Visual Basic Modes
Visual Basic Controls
Windows Form Control
Button Control
Label Control
Textbox Control
MsgBox Statement
InputBox Function
3
Why Visual Basic
• Fastest and easiest way to create
applications for Microsoft Windows
– Complete set of tools which simplify the
creation of the graphical user interface
– Rapid prototyping tool
• Internet capabilities (VBScript language)
• It can be used as a tool to develop frontend applications for database systems
• Microsoft estimate that there are over 3
million VB developers world wide
4
Visual Basic Modes
• Design Mode
– Placing, arranging, and customizing the appearance of buttons,
labels, and other controls on a form.
– Writing processing scripts (source code).
– Saving the solution.
– Making an executable file.
• Run Mode
– Executes the solution.
– Used to evaluate the workability of a part of the project.
– Used to show the user how the solution will work.
• Break Mode
– Helps the developer with debugging.
– Enables the developer to switch back to run mode or design
mode.
5
VB Integrated Development
Environment (IDE)
Title bar
Menu bar
Tool bar
Form Window
Tool
box
Properties
Window
Form
layout
window
Project
Explorer
window
6
Visual Basic Controls
• Trigger: Initiate processing
– Ex. Button, MainMenu, and Timer
• Input: Get data from user
– Ex. TextBox, RadioButton, and CheckBox
• Output: Display results to user
– Ex. Label, DataGrid, and ListView
• Organize: Group other controls
– Ex. Form, GroupBox, and Panel
• Data Access: Interface with databases
– Ex. Entire Data Group and DataGrid
7
Windows Form Control
• The window that is displayed when the
application is running.
• The IDE automatically creates a Windows
Form when you start a new project.
• This form will hold or “contain” other
controls.
8
Button Control
• React to the click of the use
• Perform a task associated with the name of the button that is
displayed on its face.
• Appearance and Use:
– Appears as a rectangular-shaped control on a form.
– Its face can display text, an image, or both.
– The face of the button should clearly indicate its function.
• Properties:
– The most common properties of the Button control are listed.
– Most properties are available for every control.
• Events:
–
–
–
–
Components are able to respond to events.
The click event is generated when the user clicks the mouse button.
You write code to handle events.
Double-click the Button control to automatically open the code window.
9
Label Control
• Used to display information to the user.
• Used to label other controls or show results of a
calculation.
• Appearance and Use:
– Appears as a rectangular area that can be filled with text.
– You have some control over size and alignment of text.
– You can include a border around the label.
• Properties:
– Many of the Button control properties apply to the Label control.
– The Text Property is the most-used property for the Label
control.
10
Textbox Control
•
•
Provides an area for the user to type while the program runs.
Appearance and Use:
– Displays as a rectangular area that provides the user a place to type.
– You can limit the user types
– You can also surround the TextBox with a border.
•
Properties:
–
–
–
–
–
–
•
Some of the TextBox control properties are only available at run time.
The value of the Text property is used most frequently.
Control of user entry is shared between properties and events.
The PasswordChar property allows you to set a security character.
TextLength property determines the number of characters contained in a textbox.
Selection… properties provide information on user selections in the TextBox
control.
Events:
– Focus means the user is currently working with the specific control.
• Enter - Occurs when input focus is received.
• KeyPress - Occurs when a key is pressed while the control has focus.
• Leave – Occurs when input focus leaves the control.
– Methods
• Enable the developer to manipulate text in a TextBox.
• Many are available to the developer.
11
MsgBox Statement
• The MsgBox statement will display information
that requires user intervention.
• Example:
– MsgBox("This is an example of a message box,
please press OK to return to the application",
vbDefaultButton1, "Message Box Sample")
2
1
3
3
1
2
12
Inputbox Function
• The InputBox() function requests information
from the user with a dialog box. It requires user
intervention.
– InputBox("Enter a value", "InputBox Sample")
13
Download