Solved

call vbscript function from asp

Posted on 2008-10-23
7
672 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:dev_work
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
glad to help.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

771 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

8 Experts available now in Live!

Get 1:1 Help Now