Solved

call vbscript function from asp

Posted on 2008-10-23
7
676 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
  • 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

813 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

11 Experts available now in Live!

Get 1:1 Help Now