Show if based on session var

G

GTN170777

Hi there,

I'm trying to only show part of my page based on a variable, I have two
Session Variables -

Session("EMPLOYEEMAXUSERS")
Session("EMPLOYERUSERS")

Now what I'm trying to do is -

ShowIf Session("EMPLOYERUSERS") < Session("EMPLOYERMAXUSERS")

I can't get this to work though,.. Any ideas input would be really
appreciated.

Thanks
 
E

Evertjan.

=?Utf-8?B?R1ROMTcwNzc3?= wrote on 07 jul 2008 in
microsoft.public.inetserver.asp.general:
ShowIf Session("EMPLOYERUSERS") < Session("EMPLOYERMAXUSERS")

If both values are [convertible to] numeric values it is simple:

<%
if +Session("EMPLOYERUSERS") < +Session("EMPLOYERMAXUSERS") then
%>
<div>Hi</div>
<%
else
%>
<div>Ho</div>
<%
end if
%>
 
D

Dooza

Evertjan. said:
=?Utf-8?B?R1ROMTcwNzc3?= wrote on 07 jul 2008 in
microsoft.public.inetserver.asp.general:
ShowIf Session("EMPLOYERUSERS") < Session("EMPLOYERMAXUSERS")

If both values are [convertible to] numeric values it is simple:

<%
if +Session("EMPLOYERUSERS") < +Session("EMPLOYERMAXUSERS") then
%>
<div>Hi</div>
<%
else
%>
<div>Ho</div>
<%
end if
%>

Evertjan, I have never seen this shortcut before, are there others like it?

Steve
 
E

Evertjan.

Dooza wrote on 07 jul 2008 in microsoft.public.inetserver.asp.general:
Evertjan. said:
=?Utf-8?B?R1ROMTcwNzc3?= wrote on 07 jul 2008 in
microsoft.public.inetserver.asp.general:
ShowIf Session("EMPLOYERUSERS") < Session("EMPLOYERMAXUSERS")

If both values are [convertible to] numeric values it is simple:

<%
if +Session("EMPLOYERUSERS") < +Session("EMPLOYERMAXUSERS") then
%>
<div>Hi</div>
<%
else
%>
<div>Ho</div>
<%
end if
%>

Evertjan, I have never seen this shortcut before, are there others
like it?

Shortcut for what? What others?

Did you try my code?
 
O

Old Pedant

If both values are [convertible to] numeric values it is simple:
<%
if +Session("EMPLOYERUSERS") < +Session("EMPLOYERMAXUSERS") then
%>

Ugh. I guess it works, but it hides the *INTENT* of the code.

Why not use the functions that are builtin just for this kind of purpose?

if CLNG(Session("EMPLOYERUSERS")) < CLNG(Session("EMPLOYERMAXUSERS")) then

Actually, using the + as Evertjan suggests is equivalent to using
CDBL( )
in both places. That's because when VBScript needs to convert a non-numeric
value to numeric, it just assumes that it should use the "widest" conversion
it knows of, which is convert-to-double. CDBL( ).

The number of byte code tokens generated (and that then have to be executed)
is identical, so the performance will be identical. Excepting that
conversion to integer via CLNG is just marginally faster as it doesn't have
to check for strings such as "3.1328E+27" and the like, as CDBL and the
implicit conversion of the + operator do.

Under the covers, VBScript accomplishes *ANY* of these using a call to the
COM function
variantChangeTypeEx( )
and that COM function has slightly different (and faster) code for
string-to-int than it does for string-to-floating-point. But we are talking
nanoseconds here, no matter what. So why not use the version that conveys
the *SENSE* of what you are trying to do, instead of relying on a hacky trick?
 
A

Anthony Jones

Old Pedant said:
If both values are [convertible to] numeric values it is simple:
<%
if +Session("EMPLOYERUSERS") < +Session("EMPLOYERMAXUSERS") then
%>

Ugh. I guess it works, but it hides the *INTENT* of the code.

Why not use the functions that are builtin just for this kind of purpose?

if CLNG(Session("EMPLOYERUSERS")) < CLNG(Session("EMPLOYERMAXUSERS")) then

Actually, using the + as Evertjan suggests is equivalent to using
CDBL( )
in both places. That's because when VBScript needs to convert a non-numeric
value to numeric, it just assumes that it should use the "widest" conversion
it knows of, which is convert-to-double. CDBL( ).

The number of byte code tokens generated (and that then have to be executed)
is identical, so the performance will be identical. Excepting that
conversion to integer via CLNG is just marginally faster as it doesn't have
to check for strings such as "3.1328E+27" and the like, as CDBL and the
implicit conversion of the + operator do.

Under the covers, VBScript accomplishes *ANY* of these using a call to the
COM function
variantChangeTypeEx( )
and that COM function has slightly different (and faster) code for
string-to-int than it does for string-to-floating-point. But we are talking
nanoseconds here, no matter what. So why not use the version that conveys
the *SENSE* of what you are trying to do, instead of relying on a hacky
trick?

Umm... Why not simply assume the content of these session variables are
numeric in the first place?

If Session("EMPLOYERUSERS") < Session("EMPLOYERMAXUSERS") Then


All this conversion marlarky seems a bit bizarre. It would make sense if
the values were coming from the QueryString but not from the Session.
 
D

Dooza

Evertjan. said:
Dooza wrote on 07 jul 2008 in microsoft.public.inetserver.asp.general:
Evertjan. said:
=?Utf-8?B?R1ROMTcwNzc3?= wrote on 07 jul 2008 in
microsoft.public.inetserver.asp.general:

ShowIf Session("EMPLOYERUSERS") < Session("EMPLOYERMAXUSERS")

If both values are [convertible to] numeric values it is simple:

<%
if +Session("EMPLOYERUSERS") < +Session("EMPLOYERMAXUSERS") then
%>
<div>Hi</div>
<%
else
%>
<div>Ho</div>
<%
end if
%>
Evertjan, I have never seen this shortcut before, are there others
like it?

Shortcut for what? What others?

I meant the + symbol for the conversion, I have never seen it before.

Steve
 
A

Anthony Jones

Dooza said:
Evertjan. said:
Dooza wrote on 07 jul 2008 in microsoft.public.inetserver.asp.general:
Evertjan. wrote:
=?Utf-8?B?R1ROMTcwNzc3?= wrote on 07 jul 2008 in
microsoft.public.inetserver.asp.general:

ShowIf Session("EMPLOYERUSERS") < Session("EMPLOYERMAXUSERS")

If both values are [convertible to] numeric values it is simple:

<%
if +Session("EMPLOYERUSERS") < +Session("EMPLOYERMAXUSERS") then
%>
<div>Hi</div>
<%
else
%>
<div>Ho</div>
<%
end if
%>

Evertjan, I have never seen this shortcut before, are there others
like it?

Shortcut for what? What others?

I meant the + symbol for the conversion, I have never seen it before.

It isn't a conversion. Its a Unary operator the result of which is the same
value as its numeric operand. However since it expects its operand to be
numeric if forces VBScript to attempt an implicit coersion of the operand to
a numeric type if it isn't already.
 
E

Evertjan.

Anthony Jones wrote on 08 jul 2008 in
microsoft.public.inetserver.asp.general:
It isn't a conversion. Its a Unary operator the result of which is
the same value as its numeric operand. However since it expects its
operand to be numeric if forces VBScript to attempt an implicit
coersion of the operand to a numeric type if it isn't already.

I would call that a conversion.
 
A

Anthony Jones

Evertjan. said:
Anthony Jones wrote on 08 jul 2008 in
microsoft.public.inetserver.asp.general:


I would call that a conversion.

Do you mean you would call the unary + operator a conversion?
 
E

Evertjan.

Anthony Jones wrote on 08 jul 2008 in
microsoft.public.inetserver.asp.general:
Do you mean you would call the unary + operator a conversion?

No, not at all.

Conversion is an action,
an operator is not an action, just a directive.

The effect [and the ment effect] is to force conversion.

Why are you nitpicking today?
Did I start it, perhaps?

;-) ;-) ;-)

btw, what better action for the unary + in ASP-VBS is there?
 
A

Anthony Jones

Evertjan. said:
Anthony Jones wrote on 08 jul 2008 in
microsoft.public.inetserver.asp.general:
Do you mean you would call the unary + operator a conversion?

No, not at all.

Conversion is an action,
an operator is not an action, just a directive.

The effect [and the ment effect] is to force conversion.

Why are you nitpicking today?
Did I start it, perhaps?

;-) ;-) ;-)

I'm just in in one of those moods I guess. ;)

(If you think that's nitpicking take a look in JScript again I get even
worse said:
btw, what better action for the unary + in ASP-VBS is there?

The only reason I think the unary + exists is that unary - also exists and
the language designers just couldn't swallow the im-balance if + didn't
exist.

It is quite an efficient means of converting although a bit obscure.
Although as I've itimated an unnecessary conversion in this case IMO.
 
O

Old Pedant

Anthony Jones said:
All this conversion marlarky seems a bit bizarre. It would make sense if
the values were coming from the QueryString but not from the Session.

Damned straight!

I'll plead "completeness," only. If the original poster was not the one who
created the Session values and was trying to work with what he was given,
then there's and excuse for the conversions.

But if he was responsible for "both ends" of the coding, then you are 100%
correct. As if you didn't already know that. <grin/>
 
O

Old Pedant

Anthony Jones said:
[the unary + operator] is quite an efficient means of converting although a bit obscure.

Ah, well now HERE *I* get to be the pedantic one and point you to my other
post.

Unary + is no more efficient (and possibly a few nanoseconds less efficient)
than using CINT( ) or CLNG( ).

In both cases, the byte code produced by the compiler is going to be
something like
Push literal string "EMPLYERUSERS"
Push builtin object (Session object, that is)
Invoke COM method [which leaves the result on top of stack]
Invoke Unary plus operator
or
Push literal string "EMPLYERUSERS"
Push builtin object (Session object, that is)
Invoke COM method [which leaves the Variant result on top of stack]
Invoke CINT/CLNG build in function
[Don't quote me on this...it's been 7 years since I messed around with the
internals of the VBS code.]

And, as I noted, CINT/CLNG and the unary plus operator will all have to
invoke the COM function VariantChangeTypeEx( ) to convert the
whatever-it-is-variant to a numeric datatype. But then the difference is
that unary + will ask to convert the variant to a vt_Double and CINT/CLNG
will ask to convert it to vt_Int, and that latter conversion is very very
marginally faster.

Since the VBS runtime uses 60 to 100 lines of C++ code to execute each byte
code token, all the surrounding stuff will take so much time in relation to
the VariantChangeTypeEx call that you'll never be able to time or see the
difference. But it's there. <grin/>
 
A

Anthony Jones

Old Pedant said:
Anthony Jones said:
[the unary + operator] is quite an efficient means of converting
although a bit obscure.

Ah, well now HERE *I* get to be the pedantic one and point you to my other
post.

Unary + is no more efficient (and possibly a few nanoseconds less efficient)
than using CINT( ) or CLNG( ).

In both cases, the byte code produced by the compiler is going to be
something like
Push literal string "EMPLYERUSERS"
Push builtin object (Session object, that is)
Invoke COM method [which leaves the result on top of stack]
Invoke Unary plus operator
or
Push literal string "EMPLYERUSERS"
Push builtin object (Session object, that is)
Invoke COM method [which leaves the Variant result on top of stack]
Invoke CINT/CLNG build in function
[Don't quote me on this...it's been 7 years since I messed around with the
internals of the VBS code.]

And, as I noted, CINT/CLNG and the unary plus operator will all have to
invoke the COM function VariantChangeTypeEx( ) to convert the
whatever-it-is-variant to a numeric datatype. But then the difference is
that unary + will ask to convert the variant to a vt_Double and CINT/CLNG
will ask to convert it to vt_Int, and that latter conversion is very very
marginally faster.

Since the VBS runtime uses 60 to 100 lines of C++ code to execute each byte
code token, all the surrounding stuff will take so much time in relation to
the VariantChangeTypeEx call that you'll never be able to time or see the
difference. But it's there. <grin/>

You could be right it might not be more efficient it just looks like it
might.

It only converts to double if the operand is not an numeric type. Otherwise
the resulting type is the same as the operand.
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top