Professional Documents
Culture Documents
Lecture 3
Variables and Calculations
txtUserName
lblGreeting
btnClose
btnShowGreeting
Examples:
Syntax of Focus:
nameOfControl.Focus()
Example:
txtFirstName.Focus
Tab Order
The focus moves from one control to another when the user
presses the Tab key.
The TabIndex can be set using the property window and the
View->Tab Order menu item.
Assigning Keyboard Access Keys to
Buttons
Windows applications almost always provide quick access
to buttons using Alt-<key> combination.
A cancel button is clicked when the user presses the Esc key.
In the form’s property window, you may set the accept button
and the cancel button.
Variables and Data Types
•Variables are computer memory locations the application can
access while running.
Invalid Identifier
13Users
get Size
box-22
IsEmpty?
Integer
Declaring a Variable
Syntax
[Dim | Private | Static] variablename As datatype [ =initialvalue]
Examples
Dim dblCarPayment As Double
Dim decItemPrice As Decimal
Examples:
Examples
Dim intQtyOrdered As Integer
intQtyOrdered = 500
-5
-intCount
+4
5 + 10
intA + intB
Writing Arithmetic Expressions
Most commonly used arithmetic operators with their precedence.
6 * 2^3 + 4 / 2 6 / 2 * 2^3 + 4
6* 8 +4/2 6/2 * 8 +4
48 +4/2 3 *8 +4
48 + 2 24 +4
50 28
Integer Division
The operator “\” performs integer division.
Example:
intHours = intMinutes \ 60
Example:
intRemainder = 17 MOD 3
x^y
Example:
•Narrowing Conversions
With narrowing conversions, a type that takes more memory is
converted into a type that takes less memory. Loss of precision
could occur with narrowing conversions. Examples:
Examples:
Syntax
Const constantname [As datatype] = expression
Examples:
Const decPI As Decimal = 3.141593D
Slide 3- 46
Specifying Decimal Positions
• Can add an integer to the format string to indicate number
of digits to display after the decimal point
• Rounding occurs when displaying fewer decimal positions
than the number contains as in the 2nd line
Slide 3- 54