Page 121 - Open Soource Technologies 304.indd
P. 121
Unit 5: VB String and Operators
There is something else you should know the Format$() function makes it easy to format dates
into strings, including times. Which shows how to display the date and time in a string note how
many ways there are to do this?
FormatS () to
display dates and
times. Format Yields This on januay I, 2000 at 1:00 A.M.
Expression
Format $ (Now, m
–d–yy) 1-1-00
Format$ (Now, m
/d/yy) 1/1/00
Format$ (Now,
mm-dd-yy) 01-01-00
Format$ (Now,
ddd, mmmm d, Friday January 1, 2000
yyy)
Format$ (Now, d 1 Jan. 2000
mmm,yyy
Format$ (Now,
hh:mm:ss 01:00:00 01/01/00
mm/dd/yy)
Format$ (Now,
hh:mm:ss 01:00:00 AM 01-01-00
AM/PM mm-dd-
yy)
You can also compare dates and times directly. For example, here_s how you loop until the
current time (returned as a string by Time$) exceeds the time the user has entered in a text box
(for example, 15:00:00); when the time is up, the program beeps and displays
a message box:
While Time$ < Text1.Text
Wend
Beep
MsgBox (“Time_s up!”)
LOVELY PROFESSIONAL UNIVERSITY 115