Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 331
  • Last Modified:

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
0
billium99
Asked:
billium99
  • 4
  • 2
1 Solution
 
Rainer JeschorCommented:
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

0
 
billium99Author Commented:
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
0
 
billium99Author Commented:
Oops that would be AND NOT
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Rainer JeschorCommented:
Hi,
imho just calling the generic function is less code and less complicated and more error-safe than everything else:
if checkIT(Session("UserType"),"1","")  OR checkIT(Session("UserType"),"2","")  OR checkIT(Session("UserType"),"7","")  

Open in new window

would simply check if your UserType has either 1 or 2 or 7.
if checkIT(Session("UserType"),"1","2")  OR checkIT(Session("UserType"),"5","2")

Open in new window

would simply check if your UserType has either 1 or 5 but not 2.
0
 
billium99Author Commented:
Thanks!
0
 
billium99Author Commented:
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
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now