You are on page 1of 21

LECTURE 3

Temporary memory locations that have:


a name
a data type, and
a scope.

The name given to the location is called


identifier.
The value stored in a variable can be changed
during the execution of the project;

The values stored in


change

constants cannot
3- 2

Variables and Named Constants must be


declared before being used in code
When you declare a Variable or Named
Constant VB

Reserves an area of memory


Assigns it a name called an Identifier

Declaration statements are coded either


Beginning of a procedure
General Declarations of a module

3- 3

DIM used to declare Variables


CONST used to declare Named Constants
Declaration includes

Name, follow Naming Convention Rules


Data Type
Required Value for Constants
Optional Initial Value for Variables

3- 4

Boolean
Byte (0 to 255)
Char
Date
String
Decimal
Object
Short (-32,768 to 32,767)

Integer
(-2,147,483,648 to
2,147,483,647)
Long (larger whole
numbers)
Single (floating point accuracy to 6
digits)
Double
(floating point accuracy to 14
points)
3- 5

Boolean 2 bytes
Byte 1 byte
Char 2 bytes
Date 8 bytes
String varies
Decimal 16 bytes
Object 4 bytes

Short 2 bytes
Integer 4 bytes
Long 8 bytes
Single 4 bytes
Double 8 bytes

3- 6

Boolean bln
Byte byt
Char chr
Date dat
String str
Decimal dec
Object depends
on type of object

Short sht
Integer int
Long lng
Single sng
Double dbl

3- 7

Dim strName, strSSN


Dim intAge

Dim decPayRate

Initialization
Dim datHireDate
Dim blnInsured
Dim lngPopulation

As String
As Short
As Decimal

= 8.25

As Date
As Boolean
As Long

Const decDISCOUNT_RATE

As Decimal

Fixed

= .15

Note:Constantsarenamedusingalluppercase
lettersEXCEPTtheprefix.
3- 8

Calculations can be performed using


properties of certain objects, variables,
constants, and numeric literals
Do Not use Strings in calculations
Values from Text property of Text Boxes

Are Strings, even if they contain numeric data

Must be converted to a Numeric Data Type

3- 9

Calculations may be performed


using the values of
numeric variables,
constants, and
properties of controls.
The result of a calculation may be
assigned to a numeric variable or
to the property of a control.
3- 10

Functions perform an action and return a


value
Expression to operate on is called the
Argument
Conversion Functions convert arguments into
a numeric value of the correct data type
Conversion Functions on Text Boxes fail if
user enters nonnumeric data or leaves the
Text Box blank

3- 11

Function
To
CInt **
CDec
CStr

Convert
Integer
Decimal
String

**CIntroundstothenearestEvenNumber
3- 12

intQuantity
decPrice
intWholeNumber
decDollars
strValue

=
=
=
=
=

CInt(txtQuantity.Text)
CDec(txtPrice.Text)
CInt(decFractionalValue)
CDec(intDollars)
CStr(decValue)

Function
Name

Argument
ToBeActedUpon

3- 13

Computers solve math formulas based on a specific order 1st, then left to
right

1. Parentheses

2. Exponentiation
3. Multiplication & Division

/
\

4. Integer Division
5. Modulus

Mod

6. Addition & Subtraction

+
3- 14

Note the use of parentheses to control

3+4*2=11 Multiplythenadd
(3+4)*2=14 Parenthesescontrol:addthenmultiply
8/4*2=4
Samelevel,lefttoright:dividethenmultiply

3- 15

Use Show Method of MessageBox to display


special type of window
Arguments of Show method

Message to display
Optional Title Bar Caption
Optional Button(s)
Optional Icon

3- 16

MessageBox.Show("Enter numeric data.", _


"Data Entry Error", _
Defaualt for .Show is
MessageBoxButtons.OK, _
OK

MessageBoxIcon.Exclamation)

3- 17

TheMessageBoxisanOverloaded

Method

Overload:Whenamethodhasseveral
argument,thatistherearemultiple
Signaturestochoosefrom
ASignaturecorrespondtothean
Argumentlist
Argumentsmustbeincludedto
exactlymatchoneofthepredefined
Signatures
3- 18

OK
OKCancel
RetryCancel
YesNo
YesNoCancel
AbortRetryIgnore

3- 19

Asterisk
Error
Exclamation
Hand
Information

None
Question
Stop
Warning

3- 20

LECTURE 3

You might also like