Google Answers Logo
View Question
 
Q: Convert VBScript to JScript ( No Answer,   1 Comment )
Question  
Subject: Convert VBScript to JScript
Category: Computers > Programming
Asked by: schulze-ga
List Price: $10.00
Posted: 25 Dec 2002 11:46 PST
Expires: 30 Jan 2003 13:57 PST
Question ID: 133308
I need help converting this to JScript:
<%

Const ksKbaURL = "http://www.kbalertz.com/websvc/latestkbs.aspx?t=%t%&c=%c%"
Const ksKbaCount = 10
Const ksKbaX = "kbAlertz"
Const ksKbaXslPath = "/kbAlertz.xsl"
Const ksKbaError="kbAlertz is unavailable at this time."

Function kbAlertz(iTech)
    On Error Resume Next
    Dim sRet, lTech, sURL
    lTech = 0
    If IsNumeric(iTech) Then
      lTech = CLng(iTech)
    End If
    If CLng(lTech) < 1 Then lTech = 1
    lTech = Trim(lTech)
    sURL = Replace(ksKbaURL, "%t%", lTech)
    sURL = Replace(sURL, "%c%", ksKbaCount)
    lTech = ksKbaX & "." & lTech

    If Application(lTech) & "" <> "" Then

      If (Application(lTech & ".Refresh") > Now()) And _ 
         (Application(lTech & ".xsl") = _ 
          Application(ksKbaX & ".xsl.Refresh")) Then
        kbAlertz = Application(lTech)
        Exit Function
      End If

    End If

    Dim oXml
    Set oXml = Server.CreateObject("Msxml2.ServerXMLHTTP")
    oXml.Open "GET", sURL , False
    oXml.send

    Dim oXsl 
    Set oXsl = Server.CreateObject("Msxml2.DOMDocument")
    oXsl.async = False
    If Application(ksKbaX & ".xsl") & "" = "" Then
      kbAlertzXSL
    End If
    oXsl.loadXML Application(ksKbaX & ".xsl")
  
    Dim oXmlD
    Set oXmlD = Server.CreateObject("Msxml2.DOMDocument")
    oXmlD.loadXML oXml.responseText
    sRet = oXmlD.transformNode(oXsl)

    If Err = 0 Then
      kbAlertz = sRet
      Application.Lock
        Application(lTech) = sRet
        Application(lTech & ".Refresh") = NoonTomorrow
        Application(lTech & ".xsl") = _ 
                      Application(ksKbaX & ".xsl.Refresh")
      Application.UnLock
    Else
      If Application(lTech) & "" <> "" Then
        kbAlertz = Application(lTech)
      Else
        kbAlertz = ksKbaError
      End If
      Err.Clear
    End If

    sRet = ""
    sURL = ""
    Set oXmlD= Nothing
    Set oXsl = Nothing
    Set oXml = Nothing
  End Function

  Sub kbAlertzXSL()
    Dim oXsl
    Set oXsl = Server.CreateObject("Msxml2.DOMDocument")
    oXsl.async = False
    oXsl.Load Server.MapPath(ksKbaXslPath)
      Application.Lock
        Application(ksKbaX & ".xsl") = oXsl.xml
        Application(ksKbaX & ".xsl.Refresh") = Now()
      Application.UnLock
    Set oXsl = Nothing
  End Sub

  Function NoonTomorrow()
    Dim dTomorrow
    dTomorrow = FormatDateTime(CDate(Now()+1), vbShortDate)
    dTomorrow = CDate(dTomorrow) + 0.5
    NoonTomorrow = CDate(dTomorrow)
  End Function
%>

Request for Question Clarification by bio-ga on 13 Jan 2003 16:37 PST
Hi,

Just for curiosity, why do you want to convert this to JavaScript?
Since this is a server-side script, it will perfectly run on an IIS
server. You won't have any performance and/or compatibility gains from
conversion.

Regards
Bio

Clarification of Question by schulze-ga on 15 Jan 2003 07:32 PST
I need it converted to a site written in jscript.

I have tried the trial and error converting but newer made it work.
That's why I seek help converting it here.

Request for Question Clarification by bio-ga on 15 Jan 2003 16:18 PST
Hi,

What web server is running on your server? Please include your
operating system too (like IIS on Windows 2000, or Apache on Linux
etc).

Also what do you mean by "a site written in JScript"? I believe you
can preserve this code without any modification and run it on your
server.

Regards
Bio

Clarification of Question by schulze-ga on 16 Jan 2003 03:46 PST
It runs on IIS, but I want it in JScript. Regardless of the fact that
it can be done otherwise.
Answer  
There is no answer at this time.

Comments  
Subject: Re: Convert VBScript to JScript
From: itonydev-ga on 10 Jan 2003 01:46 PST
 
Do you know javascript and/or vbscript?  That is very important for
context.  If you know both or have the knack for seeing patterns you
just have to go line by line and convert each statement and pay
attention to the compiler errors. Most languages have the same
constructs except for research projects and theses ;)

Some major differences between vbscript and jscript are:
1) jscript likes ; at the end of each statement
2) jscript likes if(<expr>){} syntax instead of if <expr> <crlf> End
If
3) vbscript allows you to call functions and "subs" without parameters
if you dont care about the return value, jscript requires all function
calls to include the parentheses.
jscript uses the 
        var varname [= <default]; 
syntax while vbscript uses 
        dim varname
        varname = <value> 'or set varname = <object> 
for 'setting' objects to variables.
4) exit function and exit sub are replaced by return;
5) string manipulation methods are on the string object instead of
global static methods.
6) i dont know conversion functions but if you search for "JavaScript
Converstion Functions" in google you find plenty of reference.
7) error handling is different, you will want to look up "JavaScript
Error Handling" in google as well.
8) If it is a compile error it is probably something that any client
side javascript code you find with error handling will be sufficient
for a reference.

~tony

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy