4. Projects using Intrinsic and Professional
ActiveX Controls(3)
4.
Project
using
WebBrowser:
The
WebBrowser
ActiveX
control
acts
like
an
Internet
Explorer
and
so
can
be
used
to
view
all html
documents, Thus
it
becomes
possible
to
view
all
web
pages
from
within
Visual
Basic.
oject
using
WebBrowser:
Select
Microsoft
Internet
Controls
from
the
Component
Dialog
box
and
place
them
in
the
Toolbox. The
Web
Browser
control
appears
as a
globe
in
the
tool
box. Drag
a
Web
Browser,
a
common
dialog
and
a
command
button
control
in
the
design
form.
The
WebBrowser
will
appear
as
empty
rectangle
and
increase
its
size
to
the
maximum
extent
possible. Change
the
Caption
property
of
the
command
button
as
‘browse’. The
design
window
will
look
as
shown
in
the
figure7.

Figure
7
Entering
the
Event
Code:
Open
the
code
window
by
double
clicking
the
command
button
and
enter
the
code
as
shown
in
the
figure
7a.
Private
Sub
Command1_Click()
CommonDialog1.Filter
=
"HTML
Files|*.HTM|Text
Files|
*.Text|All
Files|*.*"
CommonDialog1.ShowOpen
If
CommonDialog1.filename
<>
""
Then
WebBrowser1.Navigate
CommonDialog1.filename
End
If
End
Sub
Figure
7a
Running
the
Project:
Select
Start
from
the
Run
Menu. Then
click
the
command
button.
The
Commmon
dialog
box
will
help
you
by
displaying
the
file
open
dialog
box. Browse
through
the
folders
and
select
a
html
document. In
this
case
we
have
selected
a
html
document
containing
a
VBScript
Program
for
printing
the
calender
for
the
current
month. The
html
document
looks
as
in
the
figure
7b.
The
run
mode
window
appears
as
in
the
figure
8. You
will
,find
that
the
calender
is
displayed
for
the
current
month. In
fact
you
can
browse
any
HTML
document
with
this
Web
Browser.
<html>
<script
language="vbscript">
dim
imonth,
thisdate,
nextday,
cday
imonth
=
month(date)
document.write
"<center>"
document.write
"<font
face='verdanna'
size=5>"
document.write
"Calendar
for
"
&date
document.write
"<p>"
document.write
"<table
cellpadding=10
border><tr>"
document.write
"<td><b>sun<td><b>mon<td><b>tue<td><b>
wed<td><b>thu<td><b>fri<td><b>sat"
document.write
"<tr>"
thisdate=DateSerial(year(date),
month(date),
1)
nextday=1
for
cday
= 1
to 7
if
WeekDay(thisdate)
>
cday
Then
document.write
"<td></td>"
else
document.write
"<td
align=center>
<font
size=3>"
&
nextday
&
"</td>"
nextday
=
nextday
+ 1
thisdate
=DateSerial(year(date),
imonth,
nextday)
end
if
Next
document.write
"<tr>"
weekdays
= 1
while
month(thisdate)
=
imonth
document.write
"<td
align=center><font
size=3>"
&
nextday
&
"</td>"
nextday
=
nextday
+ 1
weekdays
=
weekdays
+ 1
if
weekdays
>
7
Then
weekdays
= 1
document.write
"<tr>"
end
if
thisdate
=
DateSerial(year(date),
imonth,
nextday)
wend
document.write
"</table>"
document.write
"</center>"
</script>
</html>
Figure
7b

Figure
8
   |