Avatar of Bill Henderson
Bill Henderson
Flag 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
ASPVB Script

Avatar of undefined
Last Comment
Bill Henderson

8/22/2022 - Mon
Rainer Jeschor

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

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
Bill Henderson

ASKER
Oops that would be AND NOT
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
ASKER CERTIFIED SOLUTION
Rainer Jeschor

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Bill Henderson

ASKER
Thanks!
Bill Henderson

ASKER
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