Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Schongar P.VBScript unleashed.1997

.pdf
Скачиваний:
45
Добавлен:
23.08.2013
Размер:
1.59 Mб
Скачать

<TR>

<TD COLSPAN=2 ALIGN=CENTER>

<INPUT TYPE="SUBMIT" NAME="BtnTest" VALUE="Test It!"></TD>

</TR>

</TABLE>

<HR COLOR="BLUE" WIDTH=85%>

<SCRIPT LANGUAGE="VBScript">

Sub BtnTest_OnClick

If CT.Value = "" then CT.Value = "0"

If CC.Value = "" then CC.Value = "0"

chart1.ChartType=CT.Value

chart1.ColorScheme=CC.Value

End Sub

</SCRIPT>

</BODY>

</HTML>

Label

The Label control is a simple, elegant control that gives you quite a bit of flexibility when working with text. You can use the Label control to insert angled text into your HTML documents. (See Figure 7.2.) Using a Timer control or any other event, you can change the properties of the Label control at runtime. Table 7.6 lists the properties for the Label control.

Figure 7.2 : The Label control can do things that normal HTML cannot.

Table 7.6. Label control properties.

Property Description

Alignment

One of the following:

 

0=Left

 

1=Right

 

2=Centered

 

3=Top

 

4=Bottom

Angle

Angle at which text is displayed

BackStyle

One of the following:

 

0=Transparent

 

1=Opaque

Caption

Label text

FontBold

One of the following:

 

0=False

 

1=True

FontName

Name of the font

FontSize

Font size

FontStrikeout One of the following:

 

0=False

 

1=True

FontUnderline One of the following:

 

0=False

 

1=True

frcolor

Font forecolor (as an RGB hexadecimal triplet)

The Label control has a Click event and has one method: About.

Listing 7.2 uses the Label control to enhance the look of a page.

Listing 7.2. Using the Label control.

<HTML>

<HEAD>

<TITLE>Tester Page</TITLE>

</HEAD>

<BODY BGCOLOR=WHITE>

<H1>Tester Page for VBScript</H1>

<HR COLOR="BLUE" WIDTH=85%>

<OBJECT ID="label1" WIDTH=75 HEIGHT=400 vspace=0

align= ALT="<H1

CLASSID="CLSID:99B42120-6EC7-11CF-A6C7-00AA00A47DD2">

<PARAM NAME="_ExtentX" VALUE="1984">

<PARAM NAME="_ExtentY" VALUE="10583">

<PARAM NAME="Caption" VALUE="VBScript">

<PARAM NAME="Angle" VALUE="90">

<PARAM NAME="Alignment" VALUE="7">

<PARAM NAME="Mode" VALUE="1">

<PARAM NAME="FillStyle" VALUE="0">

<PARAM NAME="FillStyle" VALUE="0">

<PARAM NAME="ForeColor" VALUE="#000000">

<PARAM NAME="BackColor" VALUE="#C0C0C0">

<PARAM NAME="FontName" VALUE="Times New Roman">

<PARAM NAME="FontSize" VALUE="36">

<PARAM NAME="FontItalic" VALUE="0">

<PARAM NAME="FontBold" VALUE="0">

<PARAM NAME="FontUnderline" VALUE="0">

<PARAM NAME="FontStrikeout" VALUE="0">

<PARAM NAME="TopPoints" VALUE="0">

<PARAM NAME="BotPoints" VALUE="0">

</OBJECT>

<OBJECT ID="label2" WIDTH=51 HEIGHT=400 vspace=0

align= ALT="<H1

CLASSID="CLSID:99B42120-6EC7-11CF-A6C7-00AA00A47DD2">

<PARAM NAME="_ExtentX" VALUE="1349">

<PARAM NAME="_ExtentY" VALUE="10583">

<PARAM NAME="Caption" VALUE="UNLEASHED">

<PARAM NAME="Angle" VALUE="90">

<PARAM NAME="Alignment" VALUE="6">

<PARAM NAME="Mode" VALUE="1">

<PARAM NAME="FillStyle" VALUE="0">

<PARAM NAME="FillStyle" VALUE="0">

<PARAM NAME="ForeColor" VALUE="#000000">

<PARAM NAME="BackColor" VALUE="#C0C0C0">

<PARAM NAME="FontName" VALUE="Arial">

<PARAM NAME="FontSize" VALUE="36">

<PARAM NAME="FontItalic" VALUE="0">

<PARAM NAME="FontBold" VALUE="1">

<PARAM NAME="FontUnderline" VALUE="0">

<PARAM NAME="FontStrikeout" VALUE="0">

<PARAM NAME="TopPoints" VALUE="0">

<PARAM NAME="BotPoints" VALUE="0">

</OBJECT>

</BODY>

</HTML>

You might have noticed that Listing 7.2 contains no VBScript code. I did this to show you that you can use some of these objects without writing any code at all. The really nice thing about the Label control is that you can create this vertical-text effect without making it a GIF or a JPG file. Saving bandwidth is always a good thing.

Popup Menu Control

The Popup Menu control is used to create a popup menu when the user clicks a named control or image link with the mouse on a Web page. This control is used mostly for navigational purposes. If you have a lot of links on a Web page that contains other important data, you can place those links in a popup, giving your page a cleaner look.

The Popup Menu control has only one property, ItemCount. The ItemCount property is set to the number of items in the menu. The Menuitem[] parameter tag is used to label the individual items on the page. You can then use a script to call the URL of the page that you want to navigate to.

There are five methods associated with the Popup Menu control:

AboutBox: Brings up the About box for the control

Additem(item, index): Adds item at specified index

Clear: Clears all menu items

PopUp(x, y): Where x and y are position values

RemoveItem(index): Removes item at specified index

The one event for the Popup Menu control is Click(item). The index of the item clicked is passed to the event.

Listing 7.3 contains a script that uses the Popup Menu control. A Label control's click event is used to call Pop1. Popup. Notice that we use a Select Case block to retrieve the number of the item called.

Listing 7.3. Popup Menu control example.

<HTML>

<HEAD>

<TITLE>Test Page</TITLE>

</HEAD>

<BODY BGCOLOR=WHITE>

<H1>Popup Menu Control</H1>

<HR COLOR=NAVY>

<Table BORDER BGCOLOR=YELLOW></TR><TD>

<OBJECT ID="Label1" WIDTH=165 HEIGHT=44

CLASSID="CLSID:99B42120-6EC7-11CF-A6C7-00AA00A47DD2">

<PARAM NAME="_ExtentX" VALUE="4366">

<PARAM NAME="_ExtentY" VALUE="1164">

<PARAM NAME="Caption" VALUE="Popup Menu">

<PARAM NAME="Angle" VALUE="0">

<PARAM NAME="Alignment" VALUE="4">

<PARAM NAME="Mode" VALUE="1">

<PARAM NAME="FillStyle" VALUE="0">

<PARAM NAME="FillStyle" VALUE="0">

<PARAM NAME="ForeColor" VALUE="#000000">

<PARAM NAME="BackColor" VALUE="#C0C0C0">

<PARAM NAME="FontName" VALUE="Arial">

<PARAM NAME="FontSize" VALUE="18">

<PARAM NAME="FontItalic" VALUE="0">

<PARAM NAME="FontBold" VALUE="1">

<PARAM NAME="FontUnderline" VALUE="0">

<PARAM NAME="FontStrikeout" VALUE="0">

<PARAM NAME="TopPoints" VALUE="0">

<PARAM NAME="BotPoints" VALUE="0">

</OBJECT>

</TR></TD></TABLE>

<OBJECT ID="Pop1" WIDTH=5 HEIGHT=5

CLASSID="CLSID:7823A620-9DD9-11CF-A662-00AA00C066D2">

<PARAM NAME="MenuItem[0]" VALUE="Microsoft Home Page">

<PARAM NAME="MenuItem[1]" VALUE="C|Net Online">

<PARAM NAME="MenuItem[2]" VALUE="PCWeek">

</OBJECT>

<Script Language=VBScript>

Sub Label1_Click

call Pop1.PopUp()

End Sub

Sub Pop1_Click(byVal X)

Select Case X

Case 1

top.Location="http://www.microsoft.com"

Case 2

top.Location="http://www.cnet.com"

Case 3

top.Location="http://www.pcweek.com"

End Select

End Sub

</Script>

</BODY>

</HTML>

Figure 7.3 : Popup Menu control navigates to popular URLs.

The Menu control is very similar to the PopupMenu control. The Menu control is essentially a button control that pops up a menu for the user. This control has two properties, ItemCount and Caption. ItemCount refers to the number of items in the menu. The Caption property sets the caption of the button used to show the menu.

To add items to the menu, you use the Menuitem[] parameter. You can also set the caption for the control as a parameter.

The Menu control has the same methods and events as the Popup Menu control and can be programmed the same way.

Preloader Control

You can use the Preloader control to anticipate the desires of your users and to download what, presumably, will be the next page they want to see. When they're ready to look at the page, it will pop up instantly and they will be amazed.

You need to be careful with this control. It won't do much good to preload a page unless that page is going to take a significant time to download, or any delay will cause the user to lose a feel for the flow of a number of pages.

The Preloader control has five properties:

Bytes: Amount of data read in

CacheFile: Name of the locally cached file

Enable: Enables the Preloader control (1=enable, 2=disable)

Percentage: Percentage of data read in

URL: The URL for the next page to be loaded

The Preloader control has a single method, About, and two events:

Completed: Indicates that the download has completed

Error: Indicates that an error occurred during the operation

StockTicker Control

The StockTicker control downloads information and displays it at preset intervals. The data files displayed can be in either text format or XRT format. To create a file to be used by the StockTicker control in text format, place the letters XRT on the first line and then specify the data as name-tab-value-CR/LF lines. For example:

XRT

 

 

 

Item1

Value1

Value2

Value3

Item2

Value1

Value2

Value3

Item3

Value1

Value2

Value3

The StockTicker control has the properties listed in Table 7.7.

Table 7.7. StockTicker properties.

Property

Description

BackColor

Background color

DataObjectName

URL of the data file

DataObjectActive

1=Active; 0=Inactive

ForeColor

Foreground color

OffsetValues

Vertical offset from name in pixels

ReloadInterval

Reload interval for the data file

ScrollWidth

Amount of scroll for each redraw

ScrollSpeed

Interval at which the display is scrolled

The StockTicker control has only one method, AboutBox, and no events.

Timer Control

You can use the Timer to control time-based events in your code. The timer is especially useful if you need to track a repetitive event. If you don't have a timer to use in your pages, you have to use a loop in code, which bogs down your system.

The Timer control has two properties:

Enable: Starts or stops the timer (0=disabled, 1=enabled)

Interval: Specifies the interval in milliseconds at which a Timer event will be triggered

The Timer control supports only one event: Timer. The Timer event is triggered when the value of the Interval property has been passed.

The only method supported by the Timer control is About, which provides information about the control.

Listing 7.4 uses the Timer control to activate the controls on the page. Remember that you can't directly control the HTML content of a page without reloading. You can change the properties of active controls on a page, though, and

those changes are reflected immediately. Listing 7.4 provides such an example.

Listing 7.4. Controlling objects with the timer.

<HTML>

<HEAD>

<TITLE>Changing Message Example</TITLE>

</HEAD>

<BODY BGCOLOR=WHITE>

<H1>Changing Message</H1>

<HR COLOR="YELLOW">

<TABLE BORDER BORDERCOLOR=GREEN>

<TR>

<TD>

<OBJECT ID="label1" WIDTH=555 HEIGHT=40 align= vspace=0

CLASSID="CLSID:99B42120-6EC7-11CF-A6C7-00AA00A47DD2">

<PARAM NAME="_ExtentX" VALUE="14684">

<PARAM NAME="_ExtentY" VALUE="1058">

<PARAM NAME="Caption" VALUE=" Message Box">

<PARAM NAME="Angle" VALUE="0">

<PARAM NAME="Alignment" VALUE="4">

<PARAM NAME="Mode" VALUE="1">

<PARAM NAME="FillStyle" VALUE="0">

<PARAM NAME="FillStyle" VALUE="0">

<PARAM NAME="ForeColor" VALUE="#000000">

<PARAM NAME="BackColor" VALUE="#C0C0C0">

<PARAM NAME="FontName" VALUE="Arial">

<PARAM NAME="FontSize" VALUE="14">

<PARAM NAME="FontItalic" VALUE="0">

<PARAM NAME="FontBold" VALUE="1">

<PARAM NAME="FontUnderline" VALUE="0">

<PARAM NAME="FontStrikeout" VALUE="0">

<PARAM NAME="TopPoints" VALUE="0">

<PARAM NAME="BotPoints" VALUE="0">

</OBJECT>

</TD>

</TR>

</TABLE>

<OBJECT ID="Timer1" WIDTH=39 HEIGHT=39

CLASSID="CLSID:59CCB4A0-727D-11CF-AC36-00AA00A47DD2">

<PARAM NAME="_ExtentX" VALUE="1032">

<PARAM NAME="_ExtentY" VALUE="1032">

<PARAM NAME="Interval" VALUE="3000">

</OBJECT>

<SCRIPT LANGUAGE="VBScript">

Dim x

x = 0

Sub timer1_timer

Dim Msg(3)

 

 

 

 

 

 

Msg(0)="

This is

the first message.

Number 2

is coming up!"

Msg(1)="

The second message

is

finally here."

 

Msg(2)="

Message

3, time to

go

back

to the first."

label1.caption = Msg(x)

x = x + 1

If x > 2 then x = 0

End Sub

</SCRIPT>

</BODY>