473,320 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Show if based on session var

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
Jul 7 '08 #1
14 1376
=?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.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 7 '08 #2
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?

Steve
Jul 7 '08 #3
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?

Did you try my code?
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 7 '08 #4
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?
Jul 7 '08 #5

"Old Pedant" <Ol*******@discussions.microsoft.comwrote in message
news:97**********************************@microsof t.com...
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.

--
Anthony Jones - MVP ASP/ASP.NET
Jul 8 '08 #6
Evertjan. wrote:
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.

Steve
Jul 8 '08 #7
"Dooza" <st*****@SPAM.dooza.tvwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
Evertjan. wrote:
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.

--
Anthony Jones - MVP ASP/ASP.NET
Jul 8 '08 #8
Anthony Jones wrote on 08 jul 2008 in
microsoft.public.inetserver.asp.general:
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.
I would call that a conversion.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 8 '08 #9
"Evertjan." <ex**************@interxnl.netwrote in message
news:Xn********************@194.109.133.242...
Anthony Jones wrote on 08 jul 2008 in
microsoft.public.inetserver.asp.general:
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.

I would call that a conversion.
Do you mean you would call the unary + operator a conversion?
--
Anthony Jones - MVP ASP/ASP.NET
Jul 8 '08 #10
Anthony Jones wrote on 08 jul 2008 in
microsoft.public.inetserver.asp.general:
"Evertjan." <ex**************@interxnl.netwrote in message
news:Xn********************@194.109.133.242...
>Anthony Jones wrote on 08 jul 2008 in
microsoft.public.inetserver.asp.general:
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.

I would call that a conversion.

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?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 8 '08 #11
"Evertjan." <ex**************@interxnl.netwrote in message
news:Xn********************@194.109.133.242...
Anthony Jones wrote on 08 jul 2008 in
microsoft.public.inetserver.asp.general:
"Evertjan." <ex**************@interxnl.netwrote in message
news:Xn********************@194.109.133.242...
Anthony Jones wrote on 08 jul 2008 in
microsoft.public.inetserver.asp.general:

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.

I would call that a conversion.
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 <snigger>).
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.

--
Anthony Jones - MVP ASP/ASP.NET
Jul 8 '08 #12
"Anthony Jones" wrote:
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/>

Jul 8 '08 #13
"Anthony Jones" wrote:
[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/>
Jul 8 '08 #14
"Old Pedant" <Ol*******@discussions.microsoft.comwrote in message
news:8F**********************************@microsof t.com...
"Anthony Jones" wrote:
[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.

--
Anthony Jones - MVP ASP/ASP.NET
Jul 8 '08 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Bozo Schmozo | last post by:
Greetings! I've searched groups.google.com already to see if I can determine if using PHP/MySQL (if needed) for a web site I wish to develop. As the subject indicated, it will be a content...
4
by: Morten | last post by:
Hi! I've been implementing forms based authentication in a web project. It works pretty good. When I log on by clicking the "login" button the following code is executed: if...
5
by: Rob | last post by:
I have an ASP.NET application that uses forms-based authentication. A user wishes to be able to run multiple sessions of this application simultaneously from the user's client machine. The...
5
by: Rajani | last post by:
Hello, I have a strange problem. I want to check the privilege of the login user on each page and allow to display if has suff. priv. I am storing the privilege is session variable. I am...
1
by: ad | last post by:
I want show some message to user when his session time out. How can I do that?
3
by: Mark | last post by:
I'm told that ram based cookies refer to session cookies (which the browser may still store on disk if it likes). These cookies that are destroyed when the bowser exits. If they are "session...
7
by: nugget | last post by:
Role-based security for an ASP/ASP.NET mixed environment Hello: My co-worker and I have been charged with designing role-based security for our intranet. The technologies we have to work with...
0
by: TRB_NV | last post by:
I'd been using an Access database based shopping cart, but wanted to change it so that it would use session variables. I have a form that's submitted to a page called addtocart.asp that contains...
1
by: jesibl | last post by:
Hi All, I have an ASP .NET 2.0 web based app which should change content based on a variable passed in the query string. Let's say the variable is called ID and the variations are A, B and C. ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.