Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Set session variable syntax

Posted on 2008-06-24
15
Medium Priority
?
419 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:Aleks
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

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

Author Comment

by:Aleks
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
 
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:Aleks
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 2000 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:Aleks
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article discusses how to create an extensible mechanism for linked drop downs.
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…
Suggested Courses

971 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