var = Request.QueryString(item) - why doesn't this work?!

This is a discussion on "var = Request.QueryString(item) - why doesn't this work?!" within the Classic ASP section. This forum, and the thread "var = Request.QueryString(item) - why doesn't this work?! are both part of the Program Your Website category.



 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > Classic ASP

Notices


Reply
 
LinkBack Thread Tools
  #1  
Old Jun 15th, 2006, 22:02
Reputable Member
Join Date: Mar 2005
Location: Margaritaville (a state of mind somewhere between Inebriation and San Diego), CA
Posts: 245
Thanks: 6
Thanked 0 Times in 0 Posts
var = Request.QueryString(item) - why doesn't this work?!

for the URL http://localserver/testmatrix.asp?project=AV9.12

This line:
strProject = Request.QueryString(Project)

yields this error:
Request object, ASP 0102 (0x80004005)
The function expects a string as input.
/testmatrix.asp, line 9

This works, though:
For Each item In Request.QueryString
Response.Write(item & " = " & Request.QueryString(item) & VbCrLf)
Next

Can anyone tell me why I can't assign a QueryString parameter to a string var? More importantly, what's the workaround?

Last edited by Donny Bahama; Jun 15th, 2006 at 22:04.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Jun 16th, 2006, 01:07
Up'n'Coming Member
Join Date: Apr 2006
Location: Missouri
Age: 32
Posts: 65
Thanks: 0
Thanked 0 Times in 0 Posts
Re: var = Request.QueryString(item) - why doesn't this work?!

Post your code
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Jun 16th, 2006, 03:02
Junior Member
Join Date: May 2006
Location: USA
Age: 23
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Re: var = Request.QueryString(item) - why doesn't this work?!

I may not be of much help here, but I thought it was supposed to be == not just = when setting a variable up to another one in ASP. I might be wrong though. (Sorry, C++ Programmer trying to learn ASP too).
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Jun 16th, 2006, 07:53
spinal007's Avatar
Moderator
Join Date: Mar 2004
Location: Good Ol'London
Age: 23
Posts: 1,668
Blog Entries: 1
Thanks: 1
Thanked 4 Times in 4 Posts
Re: var = Request.QueryString(item) - why doesn't this work?!

Quote:
Originally Posted by Donny Bahama
strProject = Request.QueryString(Project)

yields this error:
Request object, ASP 0102 (0x80004005)
The function expects a string as input.
/testmatrix.asp, line 9
"The function expects a string input" means you've passed an object for a string parameter


Quote:
Originally Posted by Donny Bahama
This works, though:
For Each item In Request.QueryString
Response.Write(item & " = " & Request.QueryString(item) & VbCrLf)
Next
That's because "For Each item In Request.QueryString" returns a collection of strings (keys) for the Request.QueryString collection.



How to solve this problem:
1. Check where the value of Project is assigned. Make sure it isn't Null and you have not used the Set statement. If the value is assigned by a function, make sure that doesn't return an object.

2. It's best pratice.... Always do this:
Code: Select all
strProject = Request.QueryString("" & Project)
"" & Project will implicitly convert the contents of the variable into a string before passing the parameter to the method you're calling.



*************
Quote:
Originally Posted by LearningToProgram
I may not be of much help here, but I thought it was supposed to be == not just = when setting a variable up to another one in ASP. I might be wrong though. (Sorry, C++ Programmer trying to learn ASP too).
You're right, most programming languages have a different operator for assigning and comparing variables.
The Melonheads at Microsoft decided to only use "=", which depending on the statment can be a comparisson operator OR an assignment operator.

I thought I'd mention it just to make sure there's no confusion.
Last Blog Entry: Random String in Javascript (Apr 21st, 2008)

Last edited by spinal007; Jun 16th, 2006 at 07:58.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Jun 16th, 2006, 21:25
Reputable Member
Join Date: Mar 2005
Location: Margaritaville (a state of mind somewhere between Inebriation and San Diego), CA
Posts: 245
Thanks: 6
Thanked 0 Times in 0 Posts
Re: var = Request.QueryString(item) - why doesn't this work?!

Thanks for the response, everyone! After I posted the initial question, I tried (just for the heck of it) this:
Code: Select all
strProject = Request.QueryString("project")
instead of this:
Code: Select all
strProject = Request.QueryString(project)
It worked.
Quote:
Originally Posted by spinal007
It's best pratice.... Always do this:
Code: Select all
strProject = Request.QueryString("" & Project)
"" & Project will implicitly convert the contents of the variable into a string before passing the parameter to the method you're calling.
That did not work.
Quote:
Originally Posted by spinal007
1. Check where the value of Project is assigned. Make sure it isn't Null and you have not used the Set statement. If the value is assigned by a function, make sure that doesn't return an object.
I'm not clear on what you mean, here. The value of Project is assigned in the URL/querystring. Neither it nor the strProject variable are mentioned prior to this point in my code.

As I said, it's working now, so that's good, but it seems there's a learning opportunity here.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Jun 16th, 2006, 21:31
Reputable Member
Join Date: Mar 2005
Location: Margaritaville (a state of mind somewhere between Inebriation and San Diego), CA
Posts: 245
Thanks: 6
Thanked 0 Times in 0 Posts
Re: var = Request.QueryString(item) - why doesn't this work?!

Quote:
Originally Posted by LearningToProgram
(Sorry, C++ Programmer trying to learn ASP too).
Learning ASP is largely a matter of learning VBscript. To that end, I find DevGuru's VBscript QuickRef extremely useful. As a C++ programmer, you might want to explore ASP.NET - I believe you can actually choose to use C++ as the core language in that environment.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old Jun 16th, 2006, 22:20
Junior Member
Join Date: May 2006
Location: USA
Age: 23
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Re: var = Request.QueryString(item) - why doesn't this work?!

Well I have saved this to my learning folder. I'm sure this will help me in the future. Thanks for having this issue as it has helped me out too .
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old Jun 17th, 2006, 08:43
spinal007's Avatar
Moderator
Join Date: Mar 2004
Location: Good Ol'London
Age: 23
Posts: 1,668
Blog Entries: 1
Thanks: 1
Thanked 4 Times in 4 Posts
Re: var = Request.QueryString(item) - why doesn't this work?!

RMAOFL

It seemed from your first post that Project was a variable.
ie:
Code: Select all
Dim Project
Project = "SomeStringValue"
I suppose that's my fault. I should have guessed since you appropriatelly named the variable strProject.

I didn't know the parameter in the querystring you actually wanted was "project". Or I'd have simply said...
Strings must be enclosed with "
Last Blog Entry: Random String in Javascript (Apr 21st, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
var, doesnt, work

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing wildcards in a querystring jayaime Classic ASP 0 Oct 11th, 2006 19:02
Getting an item from an array monfu ASP.NET Forum 0 Mar 29th, 2006 13:17
request.querystring breeze76 Classic ASP 5 Oct 16th, 2005 14:35
PLEASE HELP - Passing Variables in Querystring just_the_basix Classic ASP 40 Sep 3rd, 2004 10:46
Selecting database records using the QueryString courtjester Classic ASP 10 Aug 27th, 2004 19:52


All times are GMT. The time now is 14:32.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42