·天新网首页·加入收藏·设为首页·网站导航
数码笔记本手机摄像机相机MP3MP4GPS
硬件台式机网络服务器主板CPU硬盘显卡
办公投影打印传真
家电电视影院空调
游戏网游单机动漫
汽车新车购车试驾
下载驱动源码
学院开发域名
考试公务员高考考研
业界互联网通信探索
您现在的位置:天新网 > 软件开发 > Web开发 > ASP开发
用VBScript制作定制的alert弹出消息框
http://www.Q.cc 2001年12月07日
Creating customizable alert boxes using VBScript

No, we're not stabbing JavaScript in the back...just having a little harmless fun in this tutorial. The entertainment? Customizable alert boxes.

In JavaScript, alert boxes are as simplistic- and dull- as they come:

alert("Hello there")

alert.gif (3260 bytes)

Apart from the message itself, nothing is changeable in terms of the box's interface. Where JavaScript skims through, VBScript dwells on, however. Alert boxes called using the later language can be customized in ways that the former can only dream of.

A basic alert box in VBScript is produced using the following code:

<script language="VBScript">
MsgBox "Hello there"
</script>

From this point on, however, things take on a life of its own, thanks to the optional parameters the above method supports. Case in point:

MsgBox "Hello there",64,"Greetings From WA"

alert2.gif (3332 bytes)

Note the differing icon image to the left of the message, not to mention the title on top!

The below tables contain the supported values for the second parameter of MsgBox, which we'll show first, then explain how to use:

'Which buttons" Table:

Constant Rendered button(s)
0 "Ok" button
1 "Ok" AND "Cancel" buttons
2 "Abort", 'Retry", AND "Ignore" buttons
3 "Yes", 'No", AND "Cancel" buttons
4 "Yes" AND "No" button
5 "Retry" AND "Cancel" button

Default button table:

Constant Rendered button(s)
0 The first button from the left is the default button
256 The second button from the left is the default button
512 The third button from the left is the default button
768 The fourth button from the left is the default button

Icon image table:

Constant Rendered image
16

alerticon.gif (1013 bytes)

32

alerticon2.gif (1015 bytes)

48

alerticon3.gif (1015 bytes)

64

alerticon4.gif (1005 bytes)

0

Blank

The above constants are interconnected and inseparable in their use. To specify which buttons and icons to equip your VB Alert box with, add up the relevant constant in each table (in total three constants), producing the parameter. Huh? For example, the box:

alert2.gif (3332 bytes)

was produced using the parameter 0+0+64=64, since we wanted just an "Ok" button, that it be the default one, and lastly, have the "exclamation" icon image shown.

Making sure the message is across, here's another VB box, rendered using:

MsgBox "Incorrect",37,"Greetings From WA"

alert3.gif (3505 bytes)

5+0+32 is where the 37 was derived from.

-Creating customizable alert boxes using VBScript (intro)
-Determining which button was pressed/ basic flow control
-VBScript and browser compatibility

上一篇: VB Script教学-使用条件语句
下一篇: VB Script教学-VBScript 过程

Copyright © 2000-2009 www.Q.cc, All Rights Reserved.
晨新科技 版权所有 Created by TXSite.net