| home / experts / dhtml / column22 |
|
<SCRIPT LANGUAGE="VBScript" TYPE="text/vbscript">
<!--
Function getHex(num)
getHex = Hex(num)
end Function
-->
</SCRIPT>
The function above simply takes one argument and calls the build-in Hex() function to return the hexadecimal equivalent of the argument.
Notice these differences from a JavaScript function:
The getHex() function, defined above, is available to both VBScript and JavaScript. No extra statements or identifiers are necessary.
The following form illustrates this: The HTML for the form is:<FORM> <INPUT TYPE=TEXT VALUE="255" SIZE=3> <INPUT TYPE=BUTTON VALUE="JS-VB Hex" onClick="alert(getHex(this.form.elements[0].value))"> </FORM>
This only works in Explorer, of course. But you can appreciate how a browser-specific intranet might benefit from a series of such functions that in-turn call built-in VBScript functions, speeding up statement processing and reducing script size.
The required HTML is:
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
function getLength(str){
if (IE4) str = vbRTrim(str);
else {
while (str.substr(str.length-1)==" ") {
str = str.substring(0,str.length-1);
}
}
return str.length
}
//-->
</SCRIPT>
<SCRIPT LANGUAGE="VBScript" TYPE="text/vbscript">
<!--
Function vbRTrim(str)
vbRTrim = RTrim(str)
end Function
-->
</SCRIPT>
<FORM>
<INPUT TYPE=TEXT VALUE="Length should be 19 " SIZE=40>
<INPUT TYPE=BUTTON VALUE="JS-VB Length"
onClick="alert(getLength(this.form.elements[0].value))">
</FORM>
Perhaps the examples on this page have not convinced you to enhance Explorer with JavaScript-VBScript communication. They have limited functionality and were only created to introduce VBScript functions and the principles of communication. Hopefully that has been achieved.
On the remaining pages, we will create a larger and more convincing application.
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-vbFunct.html