0
votes

I have to support an old web server developed in classic ASP and VBScript. I am running on Windows 7 with IIS 7.5.

I followed all the instructions on configuring the IIS from this article. The web page loads, but it looks like the JS doesn't see functions in VBScript.

I have this code:

<%@ Language=VBScript %>
<!-- #include file="HebrewMeta_UTF8.jv"-->
<link rel="stylesheet" type="text/css" href="../Class.css">
<html>
<head>
<%
  Nm=Request("Nm")
%>
<title>my page</title>
</head>
<script LANGUAGE="javascript">
  var Nm = "<%=Nm%>";
  function onCheckPro() {
    nm = window.navigator.appName;

    if ((nm.indexOf("Explorer") == "-1") && (nm.indexOf("Netscape") == "-1")){
        alert(" Compatibility שינוי הגדרות ");

        window.open("http://www.comax.co.il/InstallTools/compatibility-view.reg");
        //alert("ניתן להפעיל באקספלורר בלבד");
        //return;
    }
    document.all.fr.src = "CheckLogInPro.asp?Kod=" + escape(Kod.value) + "&Pass=" + escape(Pass.value) + "&Date=" + vbDate();
  }
</script>
<script LANGUAGE="vbscript">
  function vbDate()
    vbDate=Cstr(Day(Date()))+"/"+Cstr(Month(Date()))+"/"+Cstr(Year(Date()))+"  "+Cstr(hour(Now()))+":"+Cstr(Minute(Now()))+":"+Cstr(Second(Now()))
  end function
</script>

I keep on getting "'vbDate' is undefined".

The script language of the site ASP is set to VBScript.

2
What you have written there is "client-side" VBScript so the client (your Internet Browser) would need to support VBScript. If your wanting to use "server-side" VBScript in Classic ASP you have two options use <script language="vbscript" runat="server"></script> or <% %>. Any code written inside the <% %> tags will be VBScript executed on the "server-side" by default (VBScript is the default scripting engine for Classic ASP).user692942
To be honest looking at your code snippet I'm not sure you get the concept of "client-side", "server-side" scripting. If your trying to execute VBScript "client-side" you need to use a Browser that supports it like Internet Explorer. But to be honest just use JavaScript it's far more accessible and supported by all major browsers.user692942
As I wrote this is not my code, I need to start support it. I have two tabs opened on my IExplorer, one to the site installed on my server (win7) and one to the old site. The old site is working fine with the vbscript, mine is not. I don't have access to the old site server, so I don't exactly know how it is configured, the only think I see is that it works fine there and doesn't work when running on my server, so I do think its a server issue.ndweck
OK found the problem, had to add my local host to the compatibility view listndweck
The point remains that using VBS client side means that your script won't work in Chrome or Firefox, you'll be restricted to using IE. It shouldn't be hard to find a javascript function to capture the current date/time. Your function onCheckPro() looks like it's checking for Netscape, which makes it at least ten years oldJohn

2 Answers

2
votes

Not an answer, but three warnings:

  1. vbDate is a predefined data type constant; using it to name a function is asking for trouble.
  2. The string concatenation in VBScript is &, not +.
  3. Volatile functions like Date() or Now() shouldn't be used more than once in an expression.

Update wrt comment:

People who like to live dangerously should look at:

WScript.Echo vbDate(), checkType(Now())

Function vbDate()
  vbDate = "vbDate is a predefined constant: >" & vbDate & "<"
End Function

Function checkType(x)
  Select Case VarType(x)
    Case vbDate
      checkType = x & " is a date"
    Case Else
      checkType = x & " is an abomination"
  End Select
End Function

output:

cscript xvbdate.vbs
vbDate is a predefined constant: >< 11/14/2014 3:48:17 PM is an abomination

output after changing the function's name:

cscript xvbdate.vbs
vbDate is a predefined constant: >7< 11/14/2014 3:56:57 PM is a date
-2
votes

before using any variable you should give a data type to that variable dim or var

vbDate

vbDate=Cstr(Day(Date()))+"/"+Cstr(Month(Date()))+"/"+Cstr(Year(Date()))+" "+Cstr(hour(Now()))+":"+Cstr(Minute(Now()))+":"+Cstr(Second(Now()))