Solved

Set session variable syntax

Posted on 2008-06-24
15
410 Views
Last Modified: 2010-04-21
Hi,

I have a page with 4 recordsets, each one returns one digit 0 - 9, so results could be:

recordset # 1 : 4
recordset # 2 : 5
recordset # 3: 9
recordset # 4: 4

I am setting a session variable to be equal to concatenating those numbers, something like: 4594

The code i have right now actually adds and gives me : 22 as result, how can i teak it to give me the 4594 result ?

<%
Session("codeid") =(SecurityCode1.Fields.Item("codenum").Value)+(Securitycode2.Fields.Item("codenum").Value)+(Secritycode3.Fields.Item("codenum").Value)+(Securitycode4.Fields.Item("codenum").Value);
%>

Thanks.
0
Comment
Question by:amucinobluedot
  • 7
  • 4
  • 4
15 Comments
 
LVL 22

Expert Comment

by:neeraj523
ID: 21854820
Here you go

<%
Session("codeid") = SecurityCode1.Fields.Item("codenum").Value & Securitycode2.Fields.Item("codenum").Value & Secritycode3.Fields.Item("codenum").Value & Securitycode4.Fields.Item("codenum").Value
%>
0
 
LVL 15

Expert Comment

by:dosth
ID: 21854824
<%
Session("codeid") =CStr(SecurityCode1.Fields.Item("codenum").Value)+CStr(Securitycode2.Fields.Item("codenum").Value)+CStr(Secritycode3.Fields.Item("codenum").Value)+CStr(Securitycode4.Fields.Item("codenum").Value);
%>
0
 
LVL 22

Expert Comment

by:neeraj523
ID: 21854832
or simplify it more

<%
Session("codeid") = SecurityCode1("codenum") & Securitycode2("codenum") & Secritycode3("codenum") & Securitycode4("codenum")
%>
0
 

Author Comment

by:amucinobluedot
ID: 21854877
First and third solution adds to '0', second one gives me an error message.
0
 

Author Comment

by:amucinobluedot
ID: 21854902
BTW 'codenum' is an INT datatype, in case that has anything to do with this.
0
 
LVL 22

Expert Comment

by:neeraj523
ID: 21854913
what you mean to "adds to '0'"

can you tell me the output of this ??
<%
Response.Write (SecurityCode1("codenum") & Securitycode2("codenum") & Secritycode3("codenum") & Securitycode4("codenum"))

Session("codeid") = SecurityCode1("codenum") & Securitycode2("codenum") & Secritycode3("codenum") & Securitycode4("codenum")
%>

0
 
LVL 15

Expert Comment

by:dosth
ID: 21854921
can you tell me the error message

when you add it add as no, so we just need to convert to CStr()

it might be your semi colon or some thing
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 15

Expert Comment

by:dosth
ID: 21854931
<%
Dim SCode
SCode = CStr(SecurityCode1("codenum")) + CStr(SecurityCode2("codenum")) + CStr(SecurityCode3("codenum")) + CStr(SecurityCode4("codenum"))
Session("codeid") =SCode
%>

Yes, it is your semicolon at the end, we just copied that. please try replacing with this
0
 

Author Comment

by:amucinobluedot
ID: 21854980
neeraj523: out put for both is '0'

dosth: the code gives me this error:

Error Type:
Microsoft JScript compilation (0x800A03EC)
Expected ';'
/BlueDot/questionnaire/questionnairemainunsolicited.asp, line 654, column 4
Dim SCode
---^

Remember I am using ASP/Javascript
0
 
LVL 15

Expert Comment

by:dosth
ID: 21855075
then you need to use

<%
var SCode;
SCode = CStr(SecurityCode1("codenum")) + CStr(SecurityCode2("codenum")) + CStr(SecurityCode3("codenum")) + CStr(SecurityCode4("codenum"));
Session("codeid") =SCode;
%>
0
 
LVL 15

Expert Comment

by:dosth
ID: 21855115
ohhhhhhhh
there is not CStr in JScript " :)

let me find the alternate
0
 
LVL 15

Accepted Solution

by:
dosth earned 500 total points
ID: 21855279
<%
var c1,c2,c3,c4;

c1 = SecurityCode1("codenum")+'';
c2 = SecurityCode2("codenum")+'';
c3 = SecurityCode3("codenum")+'';
c4 = SecurityCode4("codenum")+'';

Session("codeid") = c1 + c2 + c3 + c4;

%>

or

<%
var c1,c2,c3,c4;

c1 = SecurityCode1("codenum");
c2 = SecurityCode2("codenum");
c3 = SecurityCode3("codenum");
c4 = SecurityCode4("codenum");

Session("codeid") = c1.toString() + c2.toString() + c3.toString() + c4.toString();

%>


0
 

Author Closing Comment

by:amucinobluedot
ID: 31470105
Thanks !
0
 
LVL 22

Expert Comment

by:neeraj523
ID: 21855333
hmm so u r using javascript in asp page..

try this..

<%
Session("codeid") =(SecurityCode1.Fields.Item("codenum").Value) + "" + (Securitycode2.Fields.Item("codenum").Value) + "" + (Secritycode3.Fields.Item("codenum").Value) + "" + (Securitycode4.Fields.Item("codenum").Value);
%>
0
 
LVL 15

Expert Comment

by:dosth
ID: 21855661
thanks for the points
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

864 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

20 Experts available now in Live!

Get 1:1 Help Now