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

simple addtion!!! 2

Status
Not open for further replies.

craigward

Programmer
Nov 13, 2007
230
GB
Hi,
I have a problem for adding a verbal to itself on click of a button. i want variable a to always hold the value and add the new value to it i submit the form. At the moment it adds to itself onclick then adds the new number to itself....

Any help would be great.

Thanks

Code:
Dim a, b

a = cint(Session("numtickets"))
b = cint(a)+cint(Session("numtickets"))

response.write(b)
 
If you dimension the variable in the click everytime it will start off as a new variable rather than holding a value...

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
I have used dim but still not working. Any other ideas?

Thanks

Sergio
 
Have you tried popping up a msgbox to tell you what Session("numtickets") is?

When you say not working,
1) what value are you getting?
2) what value are you expecting?
3) what was Session("numtickets") before the response.write
 
Just do away with the b, adding to a everytime will work as you want it to, and then output a.

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Hi,

I tried the following

Code:
Dim a, b

a = cint(Session("numtickets"))

"AND ALSO TRIED"

b = cint(Session("numtickets"))+ cint(Session("numtickets"))

=(a)
=(b)


"I am using a form like the one below.  If i type a random number i.e. 2 the var (a) will display "2" and var (b) will display "4" as expected really.  What i want is for the first number to be caputured and the next time a number is added in to the <input type=text name=numtickets> i want it to add to the first number, and so on. Hope that makes sense.

<input type=text name=numtickets>
<input type=submit>

Thanks
 
What happens if you use:
Code:
a = a + cint(Session("numtickets"))
For example if numtickets is 2, you should have a = 2 on the first run and then what happens if you click again?

Hope this helps

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
If i try what you suggested and type the number 2 a = 2 if i then say type 5 instead of a becoming 7 a = 5. The number just changes dependant of what you type in but will not add.

Thanks you
 
You problem appears to be defining the variable a within the click event.

Every time you use the click event, you're creating a. Dim a outside of the event so you don't accidentall reinitialise it..

Cheers,
Dave

"Yes, I'll stop finding bugs in the software - as soon as you stop writing bugs into the software." <-- Me

For all your testing needs: Forum1393
 
I'm getting deja-vu here Dave...

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
I see what your saying but i am still having trouble.
 
All I could suggest would be to post a bit more code that might help us diagnose the problem.

Cheers

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Thats fair enough :p k I think this is going to be dificult but i will try to explain.



This code is a snipet of the bit im working on, probably won't mean much to you but ask any questions

Code:
	Session("numtickets") = Request.QueryString("numtickets")
	Session("ticketprice") = Request.QueryString("ticketprice")
	'response.write(Session("numtickets"))
	'response.end
	
	
	Dim a, b
	
	a = Session("numtickets")
	b = cint(a)+cint(Session("totaltickets"))

	response.write(b)

	Set oRs_get_event = connStr.Execute(qry_get_event)		
			
				Do while not oRs_get_event.EOF
				
				
%>


<form name="bookticket" method="post" action="StartTheBallDynamic.asp?typ=BookTicket&eventid=<%=(oRs_get_event
("eventid"))%>&contactid=<%=(Request.QueryString("contactid"))%>&
ticketprice=<%=(oRs_get_event("ticketprice"))%>">
<tr>
	<td><%=(oRs_get_event("eventtitle"))%></td>
	<td><%=(oRs_get_event("eventdate"))%></td>
	<td><%=(oRs_get_event("guestsbooked"))%></td>
	<td><%=(oRs_get_event("ticketprice"))%></td>
	
<!--	<td><%If (oRs_get_event("guestsbooked")) <= "0" Then %>Event Full<% Else %><a href="StartTheBallDynamic.asp?typ=BookTicket&eventid=<%=(oRs_get_event
("eventid"))%>&contactid=<%=(Request.QueryString("contactid"))%>" style="text-decoration:none;color:#9966FF;">Book Ticket</a><% End If %></td>-->
	
	<%If (oRs_get_event("guestsbooked")) <= "0" Then %><td>Event Full</td><% Else %><td align="center"><input type="text" size="3" name="numtickets" /></td><td align="center"><input style="background:#003063; color:#ffffff;" type="submit" size="3" value="Add" /></td><% End If %>


This s the dynamic page that does all the database work then redirects back to the code above

Code:
Else If Request.QueryString("typ") = "BookTicket" Then		
		
		dim a
		
		contactid = Request.Querystring("contactid")
		eventid = Request.Querystring("eventid")
		ticketprice	=  Request.Querystring("ticketprice")
		numtickets = Request.Form("numtickets")
		
		a = numtickets

		createtime = Now()

		'response.write(ticketprice)
		'response.end			
		
		qry_link_contact_event = "INSERT INTO wce_subcontacts (contactid,eventid) values ('"& (contactid) &"','"& (eventid) &"')"
			Set oRs_link_contact_event = connStr.Execute(qry_link_contact_event)	
		
		qry_update_maxnoguests = "UPDATE wce_event set guestsbooked = guestsbooked - '"& (numtickets) &"' WHERE eventid = '"& (eventid) &"'"
			'response.write(qry_update_maxnoguests)
			'response.end		
			Set oRs__update_maxnoguests = connStr.Execute(qry_update_maxnoguests)

			
		response.redirect("StartTheBallRegister.asp?display=event&eventid="&
(Request.Querystring("eventid"))&"&specific=yes&eventtitle="&(Request.Form
("eventtitle"))&"&contactid="&(contactid)&"&user="&(Request.Form
"contact"))&"&numtickets="&(Request.Form("numtickets"))&"&ticketprice="&
(ticketprice)&"&a="&(ticketprice)&"")
 
>I have a problem for adding a verbal to itself on click of a button. i want variable a to always hold the value and add the new value to it i submit the form. At the moment it adds to itself onclick then adds the new number to itself....
I am curious how other memebers understand the statement. I don't get it a bit.
 
Right, lets have a go at this [smile]

Rather than using a to hold the running count, how about using another session variable and using a to update that? Something like (and I can't take full credit for this code, cheers ca8msm [wink]):
Code:
Dim a As Integer
' Get the global value
a = Session("myRunningCount")
' Add the new value
a = a + cint(Session("numtickets"))
' Update the global variable
Session("myRunningCount") = a
How does that sound for you?

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
tsuji, this was my take on it:

I have a problem for adding a verbal to itself on click of a button. - I'm having trouble getting a variable to hold a running tally.

i want variable a to always hold the value and add the new value to it i submit the form. - I want the variable to hold the tally between button clicks and then when I submit the form have the new value I've submitted added to the variable holding the tally.

At the moment it adds to itself onclick then adds the new number to itself.... - When the button is clicked, the value is added to the variable, but when I click it again instead of adding the value to the value it's already holding, it just sets the variable to the value I'm trying to add to it.

Does that sound understandable?

No offence meant Craig.

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
It is a tour-de-force of hermeneutics. Don't worry, I know Craig, you've done your best.
 
[smile]

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Thanks for you help, that did the trick!!!

Well untill the next problem :p

Thanks

Again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top