Solved

call vbscript function from asp

Posted on 2008-10-23
7
681 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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

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!

Question has a verified solution.

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

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
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/…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

705 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