PDA

View Full Version : Mixing VBScript and JScript


Vladdy
11-15-2002, 03:47 PM
Hi all.

After spending quite some time on the client side of things, I got a project that involves a good share of server side scripting...

Being as lazy as I am, I would like to use JScript for the most part ( typing "{ ... }" sure beats "Function.... End Function"). Also, regular expressions are much easier with JScript.
However there is one thing that I was not able to make work in JScript the way it does in VBScript:

<% For Each strKey In Request.ServerVariables %>
<%= strKey %>: <%= Request.ServerVariables(strKey) %>
<% Next %>

Anyway, the problem at hand is mixing VBScripts and JScripts which I had tackled for the most part.
Current stumbling block I need help with is instantiating JScript class from VBScript:
[CODE]
<%@ LANGUAGE=VBSCRIPT%>

<SCRIPT LANGUAGE="JavaScript" RUNAT="Server">
function jScriptObject()
{ this.status = 'created';
}
</SCRIPT>

<%
' This line gives an error:
Set jsObjectInstance = new jScriptObject
%>
[CODE]

Is it doable at all?

Roelf
11-15-2002, 06:59 PM
i believe you can do:
<%
var variable = new Enumerator(Request.ServerVariables);
for (variable.moveFirst(); !variable.atEnd(); variable.moveNext()){
temp = variable.item();
Response.write("Variabele " + temp + " = " + Request.ServerVariables(temp) + "<br>");
}

%>
and there is no need to go to VBscript

Vladdy
11-15-2002, 08:38 PM
Thanks for the suggestion, will try it.

How about this head-ache:

TimeStamp is of Date/Time data type it MS ACCESS db:

after I open a recordset the following gives me a type mismatch error:

rs("TimeStamp") = Date();

:mad: :mad: :mad:

Roy Sinclair
11-15-2002, 09:41 PM
The default format of a date in Javascript isn't acceptable as input to a SQL date field. You'll have to reformat the date.

Try this: rs("TimeStamp") = Date().toLocaleDateString;

Vladdy
11-15-2002, 10:54 PM
Negative, it added an empty field.

Ended up with this solution:

...
rs("TimeStamp") = getDate();
...
<SCRIPT LANGUAGE="VBScript" RUNAT="server">
Function getDate
getDate = Now()
End Function
</SCRIPT>

whammy
11-16-2002, 03:25 AM
Yup, that's the solution - whether or not you have defined a language at first (VBScript is the default in ASP), you can declare either one in a script tag with "runat="server"".

:D