Link to home
Start Free TrialLog in
Avatar of Bill Henderson
Bill HendersonFlag for United States of America

asked on

Classic ASP vb syntax question pt 2

Hi.

On Q_28290100 I saw a number of solutions for checking if a value exists in a comma delimited list, but I was wondering if it possible to check if '1' is contained in the string AND if '2' is NOT contained in the string.

What would that syntax look like in this statement if we were to modify it?

instr(Session("UserType"),"1")

Open in new window


Thanks again

Bill
Avatar of Rainer Jeschor
Rainer Jeschor
Flag of Germany image

Hi,

then a separate function makes even more sense:

<%
test="1,3,7,9,10" 

if checkIT(test,"1","2")  then
%>
<div class="nav">Nav bar</div>
<%
end if
%>


<%
' functions are typically at the top or bottom of your page.
function checkIT(user_type,valueToCheckInclude, valueToCheckExclude)
     checkInclude=false
     checkExclude=true
     arrUsertype=split(user_type,",")
     for each number in arrUsertype
          if cstr(number)=cstr(valueToCheckInclude) then
               checkInclude=true
         end if
         if cstr(number)=cstr(valueToCheckExclude) then
               checkExclude=false
         end if

    next
    if checkInclude = true And checkExclude = true then
     checkIT = true
   else
     checkIT = false
   End if
end function

%>

Open in new window

Avatar of Bill Henderson

ASKER

But here's the issue - I have about 20 buttons with about 6 possible conditions. Like one button might be for 1, 3, and 7s, and another button is for 1,2 and 7. Another is 2 and 5 only.

Building the array seems like a thorough thing to do, but would lead to a huge amount of additional lines of code, compared with something smaller like the original solution. I mean, am I close with this approach?

<% if (instr(Session("UserType"),"1") or NOT instr(Session("UserType"),"2") then %> 

Open in new window


Would this work?

I can just try this in a few hours today, but was hoping to go in prepared...

Thanks for your time

Bill
Oops that would be AND NOT
ASKER CERTIFIED SOLUTION
Avatar of Rainer Jeschor
Rainer Jeschor
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks!
Hi Rainer - I just added a related question to this - Q_28306128 - would really appreciate it if you had a chance to take a look at that.

Thanks!

Bill