473,396 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Running total

How do I code variables for a simple "running total" box without using an array?

IE: I have a "Points Earned" text box that the user inputs a value into. I have another output "Total Points Earned" box that keeps a running count of all points earned every time the user inputs a new value.

I've been doing this (which is obviously wrong):

//declare variables
decimal decPointsEarned = Convert.ToDecimal(txtPointsEarned.Text);
decimal decTotalPointsEarned;

//run code
decTotalPointsEarned = decPointsEarned + decPointsEarned;

//display code
lblTotalPointsEarned = decTotalPointsEarned.ToString();
Feb 7 '10 #1
6 11160
PS - Yes, I'm a rookie. :)
Feb 7 '10 #2
ah, figured out what was going on. Never mind!

Freaking typos...
Feb 8 '10 #3
tlhintoq
3,525 Expert 2GB
I might suggest you start practicing some better coding practices. The sooner you do it right, the less difficult it is to unlearn bad habits.

Like don't use the textbox as a place to store information. That's what variable and properties are for. Textboxes are pretty GUI things for displaying information.

Make a decimal property with get and set methods. When someone sets a value to the decimal property, it's set method can then update the textbox.

Expand|Select|Wrap|Line Numbers
  1. decimal _runningtotal;
  2. decimal RunningTotal
  3. {
  4.    get
  5.    {
  6.       return _runningtotal;
  7.    }
  8.    set
  9.    {
  10.       _runningtotal = value;
  11.       if (tbTotalTextbox != null)
  12.       {
  13.          tbTotalTextbox.Text = _runningtotal.ToString();
  14.       }
  15.    }
  16. }
Now anywhere else in your code you have a decimal variable you can work with, instead of constantly converting your Textbox.Text for every calculation

Expand|Select|Wrap|Line Numbers
  1. RunningTotal += 25;
Second. Don't use textboxes for strict numeric input since you then after keep validating the user input isn't "cat" instead of '4'. Use a NumericUpDown. The user can still type a number, and you can turn off the up/down spin controls in the properties of the of control so it looks like a textbox, but only accepts numbers and you can set minimum and maximum acceptable values.
Feb 8 '10 #4
Whoa, that makes total sense. I was having troubles with user typing characters instead of numerics. I'm not sure why my c# teacher taught us the way that I showed you?! Maybe you should come teach the class!

Thanks again, dude. If you you were local Seattle, I'd totally buy you a beer right now for all the good advice. Trust that it doesn't go un-noticed.
Feb 8 '10 #5
You sure you can turn off the spin controls for a NUD? I've been looking for about an hour for a solution online to turn it off. The best I came up with is:

this.numericUpDown1.Controls[0].Hide();
OR
this.numericUpDown1.Controls[0].Visible = false;

It does in fact remove the UpDown Arrows but it leaves an indented gray background when you run it half the time and the other half of the time it's a indented white background. Totally looks weird. Sometimes it adds pixels or characters where the arrow keys would have been displayed. Seems kind of like a bug in VS.

How do you hide your spin keys? Sorry to ask all these questions as of late.
Feb 8 '10 #6
tlhintoq
3,525 Expert 2GB
You sure you can turn off the spin controls for a NUD? I've been looking for about an hour for a solution online to turn it off.
My mistake. Its the DateTimePicker that has a property of "ShowUpDown" true/false.
Feb 8 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: James Greig | last post by:
hello people, i'm just learning javascript, could someone point me in the direction of an example of the following, or give me some clues as to how it might be done: what i would like to do...
4
by: Bill Dika | last post by:
Hi I am trying to calculate a running total of a calculated textbox (tbAtStandard) in GroupFooter1 for placement in a textbox (tbTotalAtStandard) on my report in Groupfooter0. The problem...
2
by: Peter Bailey | last post by:
I have a query that creates a graph of bookings from the course start date looking back 20 weeks based on a running sum. I also have a query that counts the number of bookings before that 20 week...
3
by: ChadDiesel | last post by:
I'm new to Access and need some advice. I am trying to setup a database to print labels and reports for our shipments. I have set up a table with fields such as I have taken a snapshot of what...
1
by: ChadDiesel | last post by:
I'm new to access and need some help. I have a form with a shipment destination at the top. I then have a subform that I enter boxes for that shipment. I have several shipments going at a...
16
by: Gandalf186 | last post by:
I need to create a query that produces running totals for every group within my table for example i wish to see: - Group A 1 5 9 15 Group B
0
by: trembita | last post by:
I have to databases that I connected together using a UNION. That was not a problem. I now need to create a running total using all of the data within the UNION. I can make a running total that...
2
by: Jana | last post by:
Using Access 97. Background: I have a main report called rptTrustHeader with a subreport rptTrustDetails in the Details section of the main report. The main report is grouped by MasterClientID. ...
6
by: Stuart Shay | last post by:
Hello All: I have a array which contains the totals for each month and from this array I want to get a running total for each month decimal month = new decimal; month = 254; (Jan) month =...
3
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hi I have a webform with several entry boxes and the user enters numbers in each box. I keep a running total (just adds all of the entries together) but am posting back to the server to do this. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.