Solved

call vbscript function from asp

Posted on 2008-10-23
7
680 Views
Last Modified: 2010-04-21
I have been working on this for hours now, trying to debug my code, but I can't find the problem. I have a vbscript function defined as follows:
<html>
<head>
<title>Testing ASP</title>

<script language="vbscript">

Function GetURL()
dim URL_var
URL_var = window.location.search
GetURL = URL_var
</script>
</head>
<body>
...
</body>
</html>
In the body I have some ASP code that I would like to use to gather the information on the page. When I am initializing my variables, one of the items I need is the URI (above I am able to get it with window.location.search).

When I initialize my variable to hold the code it gives me an error. Below is how I initialize the code as well as the error:
<%
dim url_suffix
url_suffix = GetRUL()
...
%>
Error:

Microsoft VBScript runtime (0x800A000D)
Type mismatch: 'GetURL'

I can not use javascript as we are trying to convert all our pages to vbscript in ASP (javascript is turned off all the blackberry's for security reasons therefore another solution has to be developed, ie ASP). when I used javascript, it worked fine by simply assigning the windows.location.search to the variable. But since ASP does not have the same function (that I have been able to find, anyways) for the windows.location.search, I am forced to try and call a function and return a variable that has this info in it. I have also tried cstr to convert the windows.location.search to a string to see if that helped... nothing changed.

Any help is appreciated.
0
Comment
Question by:dev_work
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 16

Expert Comment

by:brad2575
ID: 22787601
you do not have an "End Function" after the function

Function GetURL()
dim URL_var
URL_var = window.location.search
GetURL = URL_var
End Function
0
 

Author Comment

by:dev_work
ID: 22787643
Actually I did have the end function, I just missed adding it to the question... sorry.
0
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 22787770
What you are doing will NOT work. This:

<script language="vbscript">
...
</script> 
causes Function GetURL() to exist on the browser only after you have requested the page. The important thing to notice is that it exists/executes on the browser.  
This, however:
<%
dim url_suffix
url_suffix = GetRUL()
...
%> 
executes on the server BEFORE the browser page finishes loading. The browser cannot execute any server function nor vice-versa. You need to make/declare the function within the <% %> tags so that it executes on the server. However window.location.search IS a browser object, so you still cannot use that. Instead you can use:
Request.Querystring

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:dev_work
ID: 22787973
Do I have to provide a key for Request.QueryString(key) to work? I want to retrieve the whole QueryString and parse it with the code that I already have and works.

I knew that the vbscript code did render on the client side and the asp on the server side. I just thought that since the vbscript was in the <head> tag it would stay in memory to be used. However, now that I think about it, how can the server see the code that is in memory on my machine... :P

After I get this QueryString to work, I will accept the solution.

Thanks
0
 
LVL 16

Expert Comment

by:brad2575
ID: 22788008
if you are just trying to get the current pages url you can do this with the Request.ServerVariable("") in ASP.

Here is a link to all the options you may need.

http://www.powerasp.com/content/new/get-current-page-url.asp
0
 

Author Closing Comment

by:dev_work
ID: 31509277
Thank you for your help. I am used to using vbscript and javascript, but relatively new to asp. Your help has saved me big time and I really appreciate it!

Cheers!
0
 
LVL 82

Expert Comment

by:hielo
ID: 22788952
glad to help.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

738 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