Documente Academic
Documente Profesional
Documente Cultură
Presentat
Series
ion
Overview on
VISUAL BASIC
6
Part III
Examples:
Dim Num_1 as Integer
Dim Age as String
Dim Reg_DOB as Date
Dim Name as String, Address as String, Num2 as Integer
(3 variable declarations in one statement)
Dim Price1, Price2, Price3 as Single
(only Price 3 is declared as Single; Price1 and Price2 are
considered Variants because they are not explicitly declared)
IT Training Module 3 VISUAL BASIC 6 10
LET’S
ANALYZE
THE
CODE!!!
Declarations Section
Procedure for
Command button 1
Procedure for
Command button 2
IT Training Module 3 VISUAL BASIC 6 11
Option Explicit – tells that no implicit declaration is
allowed
Dim Sum as Integer – declared the variable Sum as Integer
- Sum can be used by any control in the form
Description of intrinsic
constant is found below the
IT Training Module 3 window.
VISUAL BASIC 6 18
C. Operators
Types of Operators:
/ Division 15 / 5 3
+ Addition 15 + 4 19
- Subtraction 15 - 5 10
Mod Remainder of 15 Mod 4 3
division
\ Integer 25 / 4 1
division
& String “Hi ” & Hi User!
concatenation “User!”
The order of evaluation:
Parenthesis ( ), ^, *, /, \, Mod, +, -
IT Training Module 3 VISUAL BASIC 6 21
Types of Operators:
Num1 = SQR(16)
Cur_Date = Date
Example: Results:
Dim Message as String, Result as Share
Right Returns a specified Right(string,length)
number of
characters from the
right side of the
string
Example: Results:
Dim Message as String, Result as blessings
String sings
Message = “Share your blessings.” INGS
Result = RightMessage,9)
Result = Right(Message,5)
Result = UCASE(Right(Message,3))
Mid Returns a number of Mid(string,starting
characters of a position,length)
string starting from
at a position
indicated
Example: Results:
Dim Quote as String, Result as String Patience
Quote = “Patience is a Virtue” To
Result = Mid(Quote,1,8) Virtue
Result = Mid(Quote,10,2)
InStr Returns the position InStr(string1,string1
of string2 in string1 )
Example: Results:
Dim Result as String, 4
Result = InStr(1002, 2)
UCase Changes all UCase(String)
lowercase letters
into uppercase
letters
Example: Result:
Dim Warning as String, Result as String WET FLOOR
Warning = “Wet Floor”
Result = Ucase(Warning)
Example: Result:
Dim Num as String, Result as String 5
Num = 5 (as a number)
Result = Val(Num)
Commonly Used Functions:
2. Date Functions
Now Returns both the Now()
current date and
time from the
system clock
Example: 10/16/2005
Lbl1.Caption=Now() 6:30:23 PM
Date Returns the Date()
current date of
the computer
being used
Example: Result:
Dim Cur_Date as String 10/15/2000
Cur_Date = Date
Time Returns the Time()
current time of
the computer
being used
Example: Result:
Dim Cur_Time as String 2:08:34 PM
Cur_Time = Time
Format Returns a Format(string,
formatted string “specified
according to user- format”)
defined format
Example: 2006-10-16
Dim Cur_Date as Date
Lbl1.caption= Format(Cur_Date,
“yyyy-mm-dd”)
Commonly Used Functions:
Formatting Characters for Date:
Formatting Description Example Formatting Descriptio Example
Characters Characters n
m Number of 11 h Hour 8
month without
zero
mmm Short name nov hh Hour with 08
of month zero
mmmm Long name Novembe mm Minutes 30
of month r
d Day of the 9 ss Seconds 26
month
without zero
Commonly Used Functions:
3. Number Functions
Format Returns a Format(string,
formatted string “specified format”)
according to user-
defined format
Example: 0245.60
Dim Result as Single $245.60
Result = 245.6
Lbl1.caption= Format(Result,
“0000.00”)
Lbl1.caption= Format(Result,
“$##00.00”)
Formatting Characters for Numbers:
Formattin Description
g
Character
s
0 Represents a digit, with non-significant
leading and trailing zeros
# Represents a digit, without non-significant
leading and trailing zeros
. Decimal placeholder
, Thousands separator
$+-() Literal character; displayed as typed
space
Commonly Used Functions:
3. Input/Output Functions
InputBox Displays a dialog InputBox(“prompt
box with a prompt ”)
and a textbox with
the OK and
CANCEL button
Example:
InputBox ("Type your name:")
MsgBox Displays a pop-up MsgBox(“prompt”
box with a )
message and
waits the user to
click a button.
Example:
InputBox() FUNCTION
Co
de
At Run-
time
MsgBox() FUNCTION
When CANCEL
When VALIDATE
button is clicked
button is clicked
Time Allotment:
HANDS-ON EXAMPLE 2 20 minutes
ICON
S
Named Icon
Value Constant
16 vbCritical
32 vbQuestion
48 vbExclamation
64 vbInformation
Code
Message Box with Icon
Time Allotment:
HANDS-ON ACTIVITY 30 minutes