Solved

VBScript to Javascript

Posted on 2003-12-08
8
576 Views
Last Modified: 2012-05-04
I have been told that any VBScript can be transformed into Javascript.  I have this page in VBScript that needs to be converted…

[code]
<%@ Language=VBScript %>
<html>
<head>
<title>Search</title>

<script>
function viewHelp(sourcefile, w, h) {
        winPop = window.open(sourcefile,"Help","width="+w+",height="+h+",scrollbars=yes, screenX=75,screenY=75,left=75,top=75");
}
</script>
</head>

<body bgcolor="#ffffff">
<div align="center">
<table>
<tr><td class="tdWhite"><a href="javascript:viewHelp('instructions.htm', 425, 400);">Instructions</a></td></tr>
</table>
<table border="0" cellpadding="0" cellspacing="0">
  <tr>
   <td colspan="3"><img src="Logo.jpg"></td>
  </tr>
  <tr>
<td class="tdWhite" width="710" height="264" border="0" align="center">
<table>
<tr>
<td class="tdWhite" valign="top">

<%
        Dim conn, engine, i

        Set engine = CreateObject("ActiveX.SearchEngine")

        Dim Regions
        Regions = engine.GetRegions
         
        Dim RegionID
        If Request("RegionID").Count > 0 Then
                RegionID = CLng( Request("RegionID")(1))
        Else
                RegionID = Regions(0,0)
        End If
       
        engine.HugeResultAllow = True
%>

<form id="mainForm" action="search.asp" method="get">
<p class="small">Select a topic to search: <a href="javascript:viewHelp('topic.htm', 425, 200);">?</a><br>
<select id="RegionID" name="RegionID" onchange="mainForm.submit()">
<%
        For i = LBound(Regions, 2) To UBound(Regions, 2)
%>      
  <option value="<%=Regions(0,i)%>" <%If Regions(0,i) = RegionID Then Response.Write "selected"%>><%=Regions(1,i)%></option>
<%
        Next
%>
</select><br>
<p class="small">Choose a context to search: <a href="javascript:viewHelp('context.htm', 425, 300);">?</a><br>
<select size="5" id="tags" name="tags" multiple>
<%
        Dim Rules
        Rules = engine.GetRules(CLng(RegionID))
        For i = LBound(Rules, 2) To UBound(Rules, 2)
%>      
    <option value="<%=Rules(0,i)%>" selected><%=Rules(1,i)%></option>
<%
        Next
%>
</select><br>
<p class="small">Enter a search string: <a href="javascript:viewHelp('boolean.htm', 425, 500);">?</a><br>
<input id="q" name="q" value="<%=Server.HTMLEncode("" & Request("q"))%>">
&nbsp; <input type="submit" name="action" value="Search"><br>
<input type="checkbox" name="hl" <%If Request("hl").Count > 0 Then Response.Write "checked"%>> Word Highlighting
</form>
</td>
</tr>
</table>

</td>
  </tr>
</table>

<%  If Request("q").Count > 0 And Request("action").Count > 0 Then
                Dim SelectedRules
                SelectedRules = ""
                For i = 1 To Request("tags").Count
                        SelectedRules = SelectedRules & "," & Request("tags")(i)
                Next
                engine.SelectedRules = Mid(SelectedRules, 2)
                Set Session("SearchResult") = Nothing
                If engine.Search(Request("q")(1)) Then
                        Dim Documents
                        Set Documents = engine.result
                        Set Session("SearchResult") = Documents
                        If Request("hl").Count > 0 Then Session("SearchWords") = Join(engine.WorkWords, "-") Else Session("SearchWords") = ""
                        Dim entry, DocList
                        Set DocList = Documents.selectNodes("//document")
                       
                        If DocList.length < 1 Then
%>
<hr width="722">
<span class="intro"><b>No results</b></span>
<%
                        Else
%>
<span class="intro"><b>Results</b></span>
<hr width="722">
<table width="722">
<tr><th></th><th>Document</th><th>Context(s)</th></tr>
<%
                                For j = 0 To DocList.length - 1
                                        Set entry = DocList(j)
                                        Dim tags, s
                                        Set tags = entry.selectNodes("rules/rule")
                                        s = ""
                                        For k = 0 To tags.length - 1
                                                s = s & "," & tags(k).selectSingleNode("description").text
                                        Next
%>
<tr>
  <td align="right"><%=j+1%></td><td><a title="Document and path where string is located. If clicked, will display document." href="show.asp?doc=<%=entry.selectSingleNode("url").text%>&amp;words=<%=Session("SearchWords")%>"><%=entry.selectSingleNode("title").text%></a></td>
  <td> <a title="A preview of the context(s) in which the string was found. If clicked, displays a list of links according to each context." href="showdetails.asp?id=<%=entry.getAttribute("id")%>"><%= Mid(s,2) %></a></td>
</tr>
<%
                                Next
%>
</table>
<%
                        End If
                Else
%>
<p class="intro"><b>Error: <%=engine.ErrorReason%></b></p>
<%
                End If
               
%>
<%
        End If
%>
</div>

</body>
</html>
[/code]
0
Comment
Question by:JHalstead
  • 3
  • 2
  • 2
8 Comments
 
LVL 6

Assisted Solution

by:pillbug22
pillbug22 earned 250 total points
ID: 9906455
You can convert from VBScript to JScript (not JavaScript).  JScript and JavaScript are close, but not quite the same (JScript is MS's version, available to use for ASP scripting and Windows Scripting)

Most all of the functions, etc are identical between the two, but the sysntax is a little different.

MSDN: Scripting Laguages (articles, language refernce, etc)
http://msdn.microsoft.com/library/default.asp?url=/nhp/Default.asp?contentid=28001169

Language Refernce for JScript:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/js56jslrfjscriptlanguagereference.asp
0
 

Author Comment

by:JHalstead
ID: 9908223
Thanks pillbug, that will help me learn in the future, but I need that translated asap...
0
 
LVL 2

Accepted Solution

by:
PurplePerls earned 250 total points
ID: 9912124
One important info is that your actual VB code is executed on server side.
Are you aware of the server side aspect, and why do you need on server side (*.asp) to run JavaScript?

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:JHalstead
ID: 9912624
Ok, the truth of the matter is, this script works fine on an ASP enabled server, but I was tasked to create a DHTML version that would not need a server to run.  I technically don't know if this is possible but I think it would be…
0
 
LVL 2

Expert Comment

by:PurplePerls
ID: 9912795
Now that was what I assumed.
And the answer is: it would be possible, but only on that one machine where the server is running AND only when the page is invoked locally on that machine, not trough a web server.
The reason is that it is not possible to examine anything on server side what is not on client side.
Therefore you can not run a full text search on client side which does a lookup of server side repository.
Additionally you can not instantiate an ActiveX module from a web server page to lookup client side objects.

Sorry for the bad news.
0
 
LVL 6

Expert Comment

by:pillbug22
ID: 9912890
I would agree - server-side code (VBScript) isn't interchangable with client-side code (JavaScript).  The VBScript runs code on the webserver (which has to allow it), and can't access the client.

Client-side code runs on your local browser and can't access the server.  You need to be able to run code on ther server in order to use your ActiveX control.
0
 

Author Comment

by:JHalstead
ID: 9950732
Ok, now we are getting somewhere.  

In the DHTML version there would be no server.  Everything would be contained on a CD or in an EXE.  

If this code cannot be converted to be able to do this please tell me how I can close/delete this topic...
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
visual studio and gui 6 43
Help with my python script 6 154
only14 challenge 19 68
WPF - External data binding to controls inside a UserControl 2 54
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This article will show, step by step, how to integrate R code into a R Sweave document
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now