Representing Data: Constants and Variables CHAPTER THREE – Pemrograman Visual Matakuliah

advertisement
Matakuliah
Tahun
: T0063 – Pemrograman Visual
: 2009
Representing Data: Constants and Variables
CHAPTER THREE
Chapter Introduction
• Compose event procedures that perform more
sophisticated tasks.
• Focus specifically on data items.
• Continue work with Visual Basic .NET project structure.
• Determine the meaning of the term scope.
Bina Nusantara University
2
Objectives
• Differentiate between numeric and string data.
• Determine whether a data item should be a constant or
variable.
• Code constants and variables in event procedures.
• Describe the characteristics and uses of standard data
types.
• Create projects that consist of several forms.
• Explain scope and describe the domain of variables in
procedures and forms.
Bina Nusantara University
3
3.1 Data Categorization
• Two broad categories of data are numeric and string.
– Numeric data must contain only numbers.
– String data can contain any symbol.
– Numeric data is used in arithmetic calculations.
– String data cannot be used in calculations.
Bina Nusantara University
4
3.2 Constants
• Data item whose value is assigned at design time and
remains the same at run time.
• A literal constant is just a value.
• A symbolic constant is a descriptive name substituted for
a literal constant.
Bina Nusantara University
5
Standard Data Types
• Number of Bytes
– Main memory occupied by a variable.
• Range
– Largest and smallest values that can be stored in a
numeric variable of a given type.
Bina Nusantara University
6
Standard Data Types (cont.)
• Precision
– Indicates how close together two numeric values can
be.
• Speed of Arithmetic Calculation
– Differs for the different data types.
Bina Nusantara University
7
Choosing the Best Data Type
for a Variable
• Use decision rules
– Ex. Boolean is the best type for a variable that may be true or
false.
– Ex. Decimal is the best type for a dollar amount.
Bina Nusantara University
8
Declaring Variables:
The Dim Statement
• A variable declaration statement.
– Examples:
• Dim StreetAddress As String
• Dim GrossWeight As Integer
• Dim HomePhone As String
• Dim NetIncome As Decimal
• Dim CurrentStudent As Boolean
Bina Nusantara University
9
Using Variables:
The Assignment Statement
• Syntax of the Assignment Statement
– variablename = expression
• Ex. CourseCode = “CISB119”
• Run Time: The Effect of the Assignment Statement
– Evaluates expression on right side of equal sign.
– Stores value of expression in variable on left side of
equal sign.
Bina Nusantara University
10
Appearance and Use
• Multiple forms may be used for large projects.
– Each form should represent an objective.
– Each form should be clear and attractive.
• Each form is a user interface window during run time.
• All forms have the same basic components.
Bina Nusantara University
11
Properties of the Form Control
•
•
•
•
•
(Name)
AcceptButton
BackColor
CancelButton
ControlBox
Bina Nusantara University
•
•
•
•
Font
MaximizeBox
MinimizeBox
Text
12
Form as a Class
•
•
•
•
You create a class template by creating a form.
Buttons and text boxes are added to the class definition.
Events are methods added to the form class.
Many properties and methods are inherited from the
form’s superclass.
Bina Nusantara University
13
Download