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

Re: Show if based on session var by Evertjan

Evertjan
Mon Jul 07 08:18:47 CDT 2008

=?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)

Re: Show if based on session var by Dooza

Dooza
Mon Jul 07 08:44:50 CDT 2008

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

Re: Show if based on session var by Evertjan

Evertjan
Mon Jul 07 08:52:45 CDT 2008

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)

Re: Show if based on session var by OldPedant

OldPedant
Mon Jul 07 13:07:01 CDT 2008

> 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?

Re: Show if based on session var by Anthony

Anthony
Tue Jul 08 03:06:09 CDT 2008


"Old Pedant" <OldPedant@discussions.microsoft.com> wrote in message
news:975913CE-765F-4578-A4AA-078F1FD2FF39@microsoft.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



Re: Show if based on session var by Dooza

Dooza
Tue Jul 08 03:12:08 CDT 2008

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

Re: Show if based on session var by Anthony

Anthony
Tue Jul 08 04:15:05 CDT 2008

"Dooza" <steveNO@SPAM.dooza.tv> wrote in message
news:%23mJOtIN4IHA.1420@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



Re: Show if based on session var by Evertjan

Evertjan
Tue Jul 08 04:55:43 CDT 2008

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)

Re: Show if based on session var by Anthony

Anthony
Tue Jul 08 06:12:00 CDT 2008

"Evertjan." <exjxw.hannivoort@interxnl.net> wrote in message
news:Xns9AD5794EE5B3Eeejj99@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



Re: Show if based on session var by Evertjan

Evertjan
Tue Jul 08 07:27:30 CDT 2008

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

> "Evertjan." <exjxw.hannivoort@interxnl.net> wrote in message
> news:Xns9AD5794EE5B3Eeejj99@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)

Re: Show if based on session var by Anthony

Anthony
Tue Jul 08 08:02:19 CDT 2008

"Evertjan." <exjxw.hannivoort@interxnl.net> wrote in message
news:Xns9AD5930A8E70Ceejj99@194.109.133.242...
> Anthony Jones wrote on 08 jul 2008 in
> microsoft.public.inetserver.asp.general:
>
> > "Evertjan." <exjxw.hannivoort@interxnl.net> wrote in message
> > news:Xns9AD5794EE5B3Eeejj99@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



Re: Show if based on session var by OldPedant

OldPedant
Tue Jul 08 14:06:19 CDT 2008

"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/>


Re: Show if based on session var by OldPedant

OldPedant
Tue Jul 08 14:20:00 CDT 2008

"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/>



Re: Show if based on session var by Anthony

Anthony
Tue Jul 08 15:54:51 CDT 2008

"Old Pedant" <OldPedant@discussions.microsoft.com> wrote in message
news:8FF5AE7E-AC82-4820-BFF1-9DFF5ED1C85A@microsoft.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