Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Set session variable syntax

Posted on 2008-06-24
15
Medium Priority
?
418 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
[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
  • 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
The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

 

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
 
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 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: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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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…

721 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