473,326 Members | 2,110 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,326 software developers and data experts.

Textbox & Math Calculations

I'm trying to figure out the best way to accomplish a task. I need to
calculate the numerical values from
about 300+ textboxes. Basiclly I have an application that users input
checks and credit card receipts into
and the program calculates the total.. Right now I am just doing

Decimal.Parse(textbox1.Text) + Decimal.Parse(textbox2.Text) + etc...
So is this what I should be doing to accomplish what I'm trying to do? The
application works fine using
that functionality but not sure if thats the best way to code the
application..

Any suggestions welcome.

Thanks


Nov 16 '05 #1
2 2666
You could use this code to reduce the amount of code you type, It could make
it more readable. This code will check for all controls in the screen and if
that control is a textbox, it will add that data into a variable.

You could use a if condition if u do not want to add few textbox data. You
wouldnt want to add textbox like name, id and stuff like that... just use
one more condition like if((ctrl.Name != txtName) && (ctrl.Name != txtId))
and so on.

Type t = typeof(System.Windows.Forms.TextBox);

decimal numTxtCount = 0;

foreach(Control ctrl in this.Controls)
{
if (ctrl.GetType() == t)
{
numTxtCount += Decimal.Parse(ctrl.Text);
}
}

--
Tarkeshwar L
..Net Programmer
Fifth Generation Technologies

"RobRich" <ro*@fastbreakpizza.com> wrote in message
news:BfFhd.345344$3l3.263594@attbi_s03...
I'm trying to figure out the best way to accomplish a task. I need to
calculate the numerical values from
about 300+ textboxes. Basiclly I have an application that users input
checks and credit card receipts into
and the program calculates the total.. Right now I am just doing

Decimal.Parse(textbox1.Text) + Decimal.Parse(textbox2.Text) + etc...
So is this what I should be doing to accomplish what I'm trying to do? The application works fine using
that functionality but not sure if thats the best way to code the
application..

Any suggestions welcome.

Thanks

Nov 16 '05 #2
hi RobRich:

You can use for sentence to accomplish this task,looks like this
following code
public Decimal GetValue()
{
TextBox textControl = new TextBox();
string controlName = "TextBox";
Decimal textValue = 0;

for(int i = 1 ; i < 5; i++)
{
textControl = checked((TextBox)Page.FindControl(controlName + i));
textValue = textValue + Decimal.Parse(textControl.Text);
}

return textValue;

}

And you can use this method looks like following code

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
Response.Write(this.GetValue());
}


jiangyh

"RobRich" <ro*@fastbreakpizza.com> дÈëÓʼþ
news:BfFhd.345344$3l3.263594@attbi_s03...
I'm trying to figure out the best way to accomplish a task. I need to
calculate the numerical values from
about 300+ textboxes. Basiclly I have an application that users input
checks and credit card receipts into
and the program calculates the total.. Right now I am just doing

Decimal.Parse(textbox1.Text) + Decimal.Parse(textbox2.Text) + etc...
So is this what I should be doing to accomplish what I'm trying to do? The application works fine using
that functionality but not sure if thats the best way to code the
application..

Any suggestions welcome.

Thanks

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

89
by: Radioactive Man | last post by:
In python 2.3 (IDLE 1.0.3) running under windows 95, I get the following types of errors whenever I do simple arithmetic: 1st example: >>> 12.10 + 8.30 20.399999999999999 >>> 1.1 - 0.2...
7
by: R0bert Nev1lle | last post by:
Internet Explorer always presents me with a challenge (partial repost). The current issue involves emulating max-width in IE using the technique described by Svend Tofte. ...
1
by: limelight | last post by:
I have discovered a math error in the .NET framework's Log function. It returns incorrect results for varying powers of 2 that depend on whether the program is run from within the IDE or from the...
17
by: cwdjrxyz | last post by:
Javascript has a very small math function list. However there is no reason that this list can not be extended greatly. Speed is not an issue, unless you nest complicated calculations several levels...
4
by: Tony | last post by:
Using Math.pow(10000000,10) or Math.pow(10000*1000,10) returns: 9.999999999999999e+69 (Mozilla 0.8) 1e+70 (Opera 8 & Explorer 6) Is this a Mozilla bug? Ten million is a power of ten, isn't...
27
by: Daniel Vallstrom | last post by:
I'm having problems with inconsistent floating point behavior resulting in e.g. assert( x > 0.0 && putchar('\n') && x == 0.0 ); holding. (Actually, my problem is the dual one where I get...
17
by: Andreas Huber | last post by:
What follows is a discussion of my experience with .NET generics & the ..NET framework (as implemented in the Visual Studio 2005 Beta 1), which leads to questions as to why certain things are the...
7
by: Brian | last post by:
Hi, I have been trying to tune my vc7 compiled applications to perform at the same or (preferably) better speed of the same vc6 application. Both versions of my code are compiled with...
6
by: jason | last post by:
Hi, I learned my lesson about passing pointers, but now I have a question about macros. Why does the function work and the MACRO which is doing the same thing on the surface, does not work in...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.