Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array Issue

Status
Not open for further replies.

budgy

Programmer
Jan 4, 2005
73
GB
Hi Guys not sure if you can help me or not on this. Really hope you can!.. The issue is that im working on a intranet site at the moment, and the breif is that it will be piloted on some specific stores, the following code creates sessions which allow the page to be displaced in a selected pilotted store, if not then its redirected to another page. My question is how do i can simplify this code into a array of some sort?..

Any suggestions will be greatly appreciated. Thanks

-----------------------------------------------------------
<%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%>
<%
var mm_sv
mm_sv = Request.ServerVariables("REMOTE_HOST")
mm_me = "" + mm_sv;
mm_len = (mm_me.length)
var excerpt_me = mm_me.substr(2,4)
var HO_User = mm_me.substr(7,mm_len)
Session("location") = excerpt_me
Session("HO_User") = HO_User
%>
<%
if (excerpt_me == 1015)
{
Session("TrialStore") = "Yes"
}
else if (excerpt_me == 1023)
{
Session("TrialStore") = "Yes"
}
else if (excerpt_me == 2037)
{
Session("TrialStore") = "Yes"
}
else if (excerpt_me == 2132)
{
Session("TrialStore") = "Yes"
}
else if (excerpt_me == 2150)
{
Session("TrialStore") = "Yes"
}
else if (excerpt_me == 2161)
{
Session("TrialStore") = "Yes"
}
else if (excerpt_me == 2169)
{
Session("TrialStore") = "Yes"
}
else if (excerpt_me == 2181)
{
Session("TrialStore") = "Yes"
}
else if (excerpt_me == 2182)
{
Session("TrialStore") = "Yes"
}
else if (excerpt_me == 2210)
{
Session("TrialStore") = "Yes"
}
else if (excerpt_me == 2224)
{
Session("TrialStore") = "Yes"
}
else if (excerpt_me == 2263)
{
Session("TrialStore") = "Yes"
}
else if (excerpt_me == 2269)
{
Session("TrialStore") = "Yes"
}
else if (excerpt_me == 2273)
{
Session("TrialStore") = "Yes"
}
else if (excerpt_me == 2286)
{
Session("TrialStore") = "Yes"
}
else if (excerpt_me == 2288)
{
Session("TrialStore") = "Yes"
}
else if (excerpt_me == 2291)
{
Session("TrialStore") = "Yes"
}
else if (excerpt_me == 2350)
{
Session("TrialStore") = "Yes"
}
else if (excerpt_me == 2368)
{
Session("TrialStore") = "Yes"
}
else if (excerpt_me == 2382)
{
Session("TrialStore") = "Yes"
}
else if (excerpt_me == 2396)
{
Session("TrialStore") = "Yes"
}
else if (excerpt_me == 2397)
{
Session("TrialStore") = "Yes"
}
else if (excerpt_me == 2411)
{
Session("TrialStore") = "Yes"
}
else if (HO_User == 10093)
{
Session("TrialStore") = "Yes"
}
else if (HO_User == 9107)
{
Session("TrialStore") = "Yes"
}
else if (HO_User == 11513)
{
Session("TrialStore") = "Yes"
}
else if (HO_User == 10107)
{
Session("TrialStore") = "Yes"
}
else if (HO_User == 9844)
{
Session("TrialStore") = "Yes"
}
else
{
Session("TrialStore") = "No"
Response.Redirect("}
%>
-----------------------------------------------------------

"He that asks a question is a fool for a moment, he that never asks a question is a fool all his life
 
you could do an array...
or you could do this:

Code:
switch( excerpt_me ) {
  case 1015, 1023, 2037, ... :
    Session( "TrialStore" ) = "Yes";
    break;
  default:
    Session( "TrialStore" ) = "No";
    Response.Redirect("[URL unfurl="true"]http://**********/yourpay/default2.htm");[/URL]
    break;
}

*cLFlaVA
----------------------------
[tt]your mom goes to college[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
[banghead]
 
Hey clflava thanks for that, really appreciate it, would you mind explaining that bit of coding for me please?.. Ive not heard of the "switch" value before...

thanks :)

"He that asks a question is a fool for a moment, he that never asks a question is a fool all his life
 
the array way:

Code:
var myArray = new Array(1015,1023,2037,...);

function blnIsInArray(intVal, aryVals) {
    for ( var i = 0; i < aryVals.length; i++ ) {
        if ( aryVals[i] == intVal )
            return true;
    }
    return false;
}

if ( blnIsInArray( excerpt_me, myArray ) ) {
    Session( "TrialStore" ) = "Yes";
} else {
    Session( "TrialStore" ) = "No";
    Response.Redirect("[URL unfurl="true"]http://**********/yourpay/default2.htm");[/URL]
}

*cLFlaVA
----------------------------
[tt]your mom goes to college[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
[banghead]
 
the switch statement is a way to neatly organize multiple if/else statements.

Code:
[green][i]// compare the value of excerpt_me[/i][/green]
switch( excerpt_me ) {

  [green][i]// if it is 1015 or 1023 or 2037...[/i][/green]
  case 1015, 1023, 2037, ... :
    Session( "TrialStore" ) = "Yes";
    break;
  [green][i]// if it is any other value...[/i][/green]
  default:
    Session( "TrialStore" ) = "No";
    Response.Redirect("[URL unfurl="true"]http://**********/yourpay/default2.htm");[/URL]
    break;
}

*cLFlaVA
----------------------------
[tt]your mom goes to college[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
[banghead]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top