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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Building a Session Variable

Status
Not open for further replies.

craigward

Programmer
Nov 13, 2007
230
GB
Hi,

I can't get my session variable to keep adding the uniqueid's i pass it from a different page.

I am passing values from checkboxes, and submitting those to a page with the following code. I then add a few more ticks to some checkboxes, submit the form and the values from there i want to add to the session. Building up maybe hundreds of concatenated id's

Problem is they don't add the overwrite the previous id's.

Any ideas would be great. Thanks

Code:
contactid = Request.Form("uniqueid")
contactid =  contactid + Session("myRunningCount")
	
' Update the Session variable with the new uniqueid's

Session("myRunningCount") = contactid
response.write(Session("myRunningCount"))
 
That looks backwards to me, I expected:

Code:
contactid = Request.Form("uniqueid")
Session("myRunningCount") = Session("myRunningCount") +  contactid 
response.write(Session("myRunningCount"))

Wait until one of the guys who knows what they are doing posts on it, however. I'm just a hack.
 
It's also a good idea to use the ampersand (&) as a string concatenator. If your variables are numeric then + will yield the sum. If they are strings then you may need to add a separator between the values.

___________________________________________________________
If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
Steam Engine Prints
 
Thanks, It is a string of uniqueid's, i tried the & but it's not working. I just can see where the issue is coming from.

I've been on it all day and now i think i will have to try a different technique.

Thanks
 
Like I said, I know very little. Maybe:

Code:
contactid = Request.Form("uniqueid")

'see what these yield-
response.write(contactid)
response.write(Session("myRunningCount"))

Session("myRunningCount") = CStr(Session("myRunningCount")) & "," & CStr(contactid) 

'how about now-
response.write(Session("myRunningCount"))

 
In any case, if contactid is numeric and that you want to apply numeric operation on it or with it, you have to convert it to numeric type(s). If it is expected to be an integer, do something like this.
[tt]
contactid = Request.Form("uniqueid")
if isnumeric(contactid) then
contactid=cint(contactid)
else
'decide how you want to handle this case.
end if
[/tt]
Same can be said to Session("myRunningCount").
 
Thanks guys.

I got it working, it was an issue with the session variable. Because i had done so much testing and didn't clear the session. It couldn't store the values. I renamed the variable to something new and it just started working.

nearly a whole day to figure that out...

Thanks for all you help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top