spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / dhtml / column22
Developer News
Google Chrome Playing Catch-Up on Extensions
Open Solutions Alliance Gets New Leadership
Red Hat Spacewalk Expands Linux Management
Logo

JavaScript Enhancement with VBScript
the VBScript functions


makeMsgBox()

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
ArgumentValueDisplay
icon0No icon displayed
1
2
3
4
buts0
1
2
3
4
5
defbut0
1
2
mods0Application Modal
1System Modal

The makeMsgBox() function takes six arguments:

  1. title - a string to be displayed in the dialog title bar
  2. mess - a string to be displayed as the message to the user
  3. icon - an integer between 0 and 4, inclusive, denoting the icon to be displayed (refer to table)
  4. buts - an integer between 0 and 5, inclusive, denoting the button group to be used (refer to table)
  5. defbut - an integer between 0 and 2, inclusive, denoting the default button (refer to table)
  6. mods - an integer, either 0 or 1, denoting the modality of the dialog (refer to table)

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.


makeInputBox()

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 Function
The makeInputBox() function takes three arguments, the same three arguments used by the built-in InputBox() function:
  1. title - a string to be displayed in the dialog title bar
  2. mess - a string to be displayed as the message to the user (a prompt)
  3. def - a string to be displayed in the input area as the default response

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.

The Complete VBScript Code

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

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP · Working with the DOM Stylesheets Collection
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
MS Access and MySQL · Cisco AutoQoS: VoIP QoS for Mere Mortals · While VoIP Adoption Explodes in Enterprise, Carrier Spending Lags

All Rights Reserved. Legal Notices.
Created: Nov. 18, 1998
Revised: Nov. 18, 1998

URL: http://www.webreference.com/dhtml/column22/js-vbNewvb.html