Solved

Set session variable syntax

Posted on 2008-06-24
15
409 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
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 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

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

17 Experts available now in Live!

Get 1:1 Help Now