Solved

Classic ASP vb syntax question pt 2

Posted on 2013-11-10
6
319 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now