| home / experts / dhtml / column22 |
|

Our first function will be used to create a VBScript Message Box, and will be called by JavaScript in place of alert() and confirm():
Function makeMsgBox(title,mess,icon,buts,defbut,mods) butVal = buts + (icon*16) + (defbut*256) + (mods*4096) makeMsgBox = MsgBox(mess,butVal,title) End Function
| Argument | Value | Display | |
| icon | 0 | No icon displayed | |
| 1 | |||
| 2 | |||
| 3 | |||
| 4 | |||
| buts | 0 | ||
| 1 | |||
| 2 | |||
| 3 | |||
| 4 | |||
| 5 | |||
| defbut | 0 | ||
| 1 | |||
| 2 | |||
| mods | 0 | Application Modal | |
| 1 | System Modal | ||
The makeMsgBox() function takes six arguments:
When makeMsgBox() is called, it must first calculate the true value of the third to sixth arguments (icon,buts,defbut,mods) and then add them up:
butVal = buts + (icon*16) + (defbut*256) + (mods*4096)
The butVal variable should now store the correct integer for use as the buttons (second) argument of MsgBox(). So, we call MsgBox(), and account for a return value:
makeMsgBox = MsgBox(mess,butVal,title)
Since JavaScript can call makeMsgBox(), we have created a function to produce VBScript message dialogs from JavaScript.
Our only other VBScript function creates a VBScript Input Box, and will be called by JavaScript in place of prompt():
Function makeInputBox(title,mess,def) makeInputBox = InputBox(mess,title,def) End FunctionThe makeInputBox() function takes three arguments, the same three arguments used by the built-in InputBox() function:
We simply take the arguments and pass them to InputBox(), although in a different order. I thought the dialog title should come first, so our custom functions take the title as the first argument. It seemed more logical.
That's it for the VBScript! Simple enough. All we need are the two short functions, repeated here:
<SCRIPT LANGUAGE=VBScript TYPE="text/vbscript"> <!-- Function makeMsgBox(title,mess,icon,buts,defbut,mods) butVal = buts + (icon*16) + (defbut*256) + (mods*4096) makeMsgBox = MsgBox(mess,butVal,title) End Function Function makeInputBox(title,pr,def) makeInputBox = InputBox(pr,title,def) End Function --> </SCRIPT>
Now, JavaScript can take over.
Produced by Peter Belesis and
All Rights Reserved. Legal Notices.
Created: Nov. 18, 1998
Revised: Nov. 18, 1998
URL: http://www.webreference.com/dhtml/column22/js-vbNewvb.html