Solved

classic aspvb syntax question

Posted on 2013-11-09
8
403 Views
Last Modified: 2013-11-10
Hi,

I have an old asp site that I need to modify. We have a menu item that shows under a certain condition with a usertype field:

  <% IF Session("UserType") = 1 OR Session("UserType") = 7 THEN %> 

Open in new window


and then we show the menu item.

We recently modified a database field so that a single user record can be assigned multiple types in a comma delimited list. So instead of UserType=1, for our condition, we need to check if Session("UserType") contains 1 in a comma delimited list.

assuming users will have values like 1,7,8 or 1,3,7 how can I scan and confirm a "contains" condition in asp vb?

Thank you

Bill
0
Comment
Question by:billium99
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 200 total points
ID: 39636441
Assuming no number bigger than 9 then you can do
instr(Session("UserType"),"1")

If greater than 9 then
instr(","&Session("UserType")&",",",1,")
0
 
LVL 53

Assisted Solution

by:Scott Fell, EE MVE
Scott Fell,  EE MVE earned 150 total points
ID: 39636455
<%
test="1,3,7,9,10" 

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


<%
' functions are typically at the top or bottom of your page.
function checkIT(user_type)
     checkIT=0
     arrUsertype=split(user_type,",")
     for each number in arrUsertype
          if cstr(number)="1" then
               checkIT=1
         end if
    next
end function

%>

Open in new window

0
 
LVL 44

Assisted Solution

by:Rainer Jeschor
Rainer Jeschor earned 150 total points
ID: 39636646
Hi,
I would go the route with padas solution BUT would extend it a little bit - just to pass the check parameter as well:
<%
test="1,3,7,9,10" 

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


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

%>

Open in new window


HTH
Rainer
0
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
LVL 1

Author Comment

by:billium99
ID: 39636894
Thanks All - now Gary's solution is clearly the simplest, and right now all values are 1 - 8, but just to clarify, the second example assumes the number MUST be greater than 9?

So truly if we get to 10 user types, we need to use Pradas or Rainer's solutions?
0
 
LVL 44

Expert Comment

by:Rainer Jeschor
ID: 39636918
Hi,
Gary`s is the quickest one - but hard to read and you have always to add the "," before and after your session variable. This will work for any number but it could be not as error save as Padas/my solution due to the extras you have to add.

Padas solution is the right one in terms of best practices as it creates the array with the distinct values and then runs the compare.

My extension to Padas solution just make it usable for any check you want to run - check for 5 or 10 or ...

Just my 2ct
Rainer
0
 
LVL 1

Author Comment

by:billium99
ID: 39636926
OK thx - I have another question related to this that I will post right now, to not abuse my points. =)
0
 
LVL 1

Author Closing Comment

by:billium99
ID: 39636927
Thanks for the help
0
 
LVL 58

Expert Comment

by:Gary
ID: 39637063
Don't actually see a problem with adding a comma, it just makes the number distinct to do an instr check
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

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

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

615 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