Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Common Constants between JavaScript and VBScript in ASP 1

Status
Not open for further replies.

Ziggurat

Programmer
Jun 6, 2001
81
GB
Dear All,

A quick question.

Can both VBScript and JavaScript access the same constant. If the constant has been defined as

Const SOME_VALUE = 10

in an include file (eg abc.inc) ?

If not, what is the best way to share constants between them ?

Ziggurat
 
The keywords are not the same in VBS and JS (for exemple, "const" is VBS). So I don't think you can do it. Water is not bad as long as it stays out human body ;-)
 
You can do something like:
Code:
<html>
<head>
<script language=vbscript>
Const constOne = 387
Const constTwo = 17
</script>
<script language=javascript>
function b1Click()
{ alert(constOne) }
</script>
<script language=vbscript>
Sub b2Click()
  alert constTwo
End Sub
</script>
</head>
<body>
<input type=button name=button1
  id=button1 value=&quot;Try me&quot; onclick=&quot;b1Click()&quot;>
<input type=button name=button2
  id=button2 value=&quot;Try me too&quot; onclick=&quot;b2Click()&quot;>
</body>
</html>
So I can't see why the constants cannot be in an include of some sort. Just be sure you using naming conventions that work in both languages.

For WSH scripts you'd need to use the .WSF file format instead of .JS or .VBS though. Otherwise you have no way to indicate which language each fragment is written in. ASP should let you intermix the two script languages just as esily using the proper script tags.
 
A star for diletante for his post. Water is not bad as long as it stays out human body ;-)
 
Targol and dilletante, thank you for taking the trouble to answer my question.

I now know what to do.

Viva La Tek-Tips

Ziggurat

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top