getting response string problem

M

Mr. x

Hello,

I have declared in my program (*.aspx) something like this :

<%@ Page Language="VB" Debug="true" %>
....

<%
dim current_view_page
current_view_page = "1"

if not (Request.QueryString is nothing) then
current_view_page = Request.QueryString
end if

%>


in the body section I put something like this :

....
<% if current_view_page = "1" then
response.write(" .... ")
end if
%>


I got an error message :

Operator is not valid for type 'HttpValueCollection' and string "1".

Why ?

Thanks :)
 
F

Frank Oquendo

Mr. x said:
Operator is not valid for type 'HttpValueCollection' and string "1".

Why ?

The QueryString object is a collection of name/value pairs, not an
actual string. Try something like this instead:

If current_view_page.Item(<nameOfParam>) = "1" Then

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)
 
S

Scott M.

Actually, the value of the name/value pair IS a string and should be
accessed as such:

<%
dim current_view_page
current_view_page = "1"

if Request.QueryString <> "" then
current_view_page = Request.QueryString
end if
%>

By the way, you are using VB.NET now, not VB 6.0 and classic ASP so remember
to declare your variable types.
 
F

Frank Oquendo

Scott said:
Actually, the value of the name/value pair IS a string and should be
accessed as such:

That point was never argued. What I said is that a NameValueCollection
is not a string. In the code posted, the user is attempting to see if a
NameValueCollection object is equal to "1". That's an invalid comparison
as well as an invalid assignment.

I was surprised to see he got away wth the assignment in the first place
until you pointed out the lack of type declarations.

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)
 
S

Scott M.

Frank Oquendo said:
That point was never argued. What I said is that a NameValueCollection
is not a string. In the code posted, the user is attempting to see if a
NameValueCollection object is equal to "1". That's an invalid comparison
as well as an invalid assignment.

I see what you are saying, but to clarify: Request.QueryString does return
a string. It may be several name/value pairs strung together and, yes,
QueryString is a collection, but when accessed via Request.QueryString, you
get a string value back. Because he did not specify a specific name (or
index) to retrieve just means he'll get the whole string back and that is
his problem. As you pointed out, he's trying to evaluate the whole string
(names & values) against one particular value for one particular key in the
collection.

My main point was that he was using "Not Is Nothing" when he should have
been using <> "".

He is assigning the whole QueryString to "current_view_page" and then later
checking "current_view_page" for a value of "1", rather than either
assigning "current_view_page" just the value of one of the keys in the
QueryString (which hopefully contains a value of "1") or when he's checking
the value of "current_view_page", he should see if it contains "1" rather
than if it = "1".

Sorry for any confusion.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top