Solved

Classic ASP vb syntax question pt 2

Posted on 2013-11-10
6
321 Views
Last Modified: 2013-11-28
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
Comment
Question by:billium99
  • 4
  • 2
6 Comments
 
LVL 44

Expert Comment

by:Rainer Jeschor
ID: 39636944
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
 
LVL 1

Author Comment

by:billium99
ID: 39636957
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
 
LVL 1

Author Comment

by:billium99
ID: 39636961
Oops that would be AND NOT
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 44

Accepted Solution

by:
Rainer Jeschor earned 500 total points
ID: 39636993
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
 
LVL 1

Author Closing Comment

by:billium99
ID: 39637020
Thanks!
0
 
LVL 1

Author Comment

by:billium99
ID: 39683893
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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question