473,813 Members | 3,663 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to apply mathematic calculation on textbox.

6 New Member
i m new to .net programing and dont know how to apply mathematic calculation on the text box. i has the idea to do this thing using auto post back but i dont know what is the exact syntax which will perform the required operation like add, subtract, %calculation.
May 6 '08 #1
7 9218
Frinavale
9,735 Recognized Expert Moderator Expert
i m new to .net programing and dont know how to apply mathematic calculation on the text box. i has the idea to do this thing using auto post back but i dont know what is the exact syntax which will perform the required operation like add, subtract, %calculation.
So you have a TextBox that has some text in it.
On the server, when you click a button, take this text and parse it into an Integer or Double (or whatever you want to use) and then perform your mathematical operation on this variable.

eg:
Expand|Select|Wrap|Line Numbers
  1.    Protected Sub Btn_Add_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Btn_Add.Click
  2.  
  3.         Try
  4.                Dim myNumber As Integer = Integer.Parse(theNumberTextBox.Text)
  5.                Dim result As Integer = myNumber + 20
  6.                myResultLabel.Text = result.ToString
  7.          Catch ex As ArgumentNullException
  8.                 'number supplied was nothing
  9.                 myResultLabel.Text = "Please Supply a Number"
  10.          Catch ex As FormatException
  11.                 'number supplied was not a number
  12.                 myResultLabel.Text = "Please Supply a Number"
  13.          Catch ex As OverflowException
  14.                 'number supplied was a number too large or too small to be an Integer
  15.                  myResultLabel.Text = "Please Supply a Valid Number"
  16.  
  17.             End Try
  18.    End Sub
  19.  
-Frinny
May 6 '08 #2
Curtis Rutland
3,256 Recognized Expert Specialist
Just for clarification, are you wanting to input a number in a TextBox, and then apply some calculation to it? Or do you want to put a mathematical statement into a TextBox and have the program solve it?

Also, what language (VB/C#)?

i m new to .net programing and dont know how to apply mathematic calculation on the text box. i has the idea to do this thing using auto post back but i dont know what is the exact syntax which will perform the required operation like add, subtract, %calculation.
May 6 '08 #3
vinay2110
6 New Member
Just for clarification, are you wanting to input a number in a TextBox, and then apply some calculation to it? Or do you want to put a mathematical statement into a TextBox and have the program solve it?

Also, what language (VB/C#)?



i want to input number in that textboxes.the only thing i want that the result of these calculation will be displayed in other textboxes. i m using C# .please send me solution to this problem i will be greatly thankful to you.
May 8 '08 #4
vinay2110
6 New Member
So you have a TextBox that has some text in it.
On the server, when you click a button, take this text and parse it into an Integer or Double (or whatever you want to use) and then perform your mathematical operation on this variable.

eg:
Expand|Select|Wrap|Line Numbers
  1.    Protected Sub Btn_Add_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Btn_Add.Click
  2.  
  3.         Try
  4.                Dim myNumber As Integer = Integer.Parse(theNumberTextBox.Text)
  5.                Dim result As Integer = myNumber + 20
  6.                myResultLabel.Text = result.ToString
  7.          Catch ex As ArgumentNullException
  8.                 'number supplied was nothing
  9.                 myResultLabel.Text = "Please Supply a Number"
  10.          Catch ex As FormatException
  11.                 'number supplied was not a number
  12.                 myResultLabel.Text = "Please Supply a Number"
  13.          Catch ex As OverflowException
  14.                 'number supplied was a number too large or too small to be an Integer
  15.                  myResultLabel.Text = "Please Supply a Valid Number"
  16.  
  17.             End Try
  18.    End Sub
  19.  
-Frinny


thanks for sending the reply but i m using c# and i wants that i input the number s in the textboxes and the result will be shown in the another textbox . i m using auto post back property for this.please send me solution to this problem
i will be greatly thankful to you.
May 8 '08 #5
Svinja
25 New Member
Hi, this sample takes two number from textBox1 and textBox2, adds them, and outputs them to textBox3:
Expand|Select|Wrap|Line Numbers
  1. Int32 number1 = Convert.ToInt32(textBox1.Text);
  2. Int32 number2 = Convert.ToInt32(textBox2.Text);
  3. Int32 number3 = number1 + number2;
  4. textBox3.Text = number3.ToString();
  5.  
May 8 '08 #6
Frinavale
9,735 Recognized Expert Moderator Expert
thanks for sending the reply but i m using c# and i wants that i input the number s in the textboxes and the result will be shown in the another textbox . i m using auto post back property for this.please send me solution to this problem
i will be greatly thankful to you.

In the future please specify what language you are using in advanced. Visual Basic and C# .NET work the same way, the only difference is the syntax. Therefore if I post VB.NET code you should be able to get the concepts and apply it in your C# code.

The experts on this site are more than happy to help you with your problems but they cannot do your assignment/program for you. Attempt the assignment/program yourself first and post questions regarding any difficulties you have or about a particular function of the code that you don't know how to achieve.

I do not understand why you are using AutoPostback on your text boxes...normall y people have 2 TextBoxes and a button that represents the calculation that you want to perform on the TextBox's Text.

Eg

TextboxWithValu e1 TextboxWithValu e2

ButtonForAdditi on ButtonForSubtra ction ButtonForDivisi on ButtonForModulo us

TextboxWithResu lt



Then when the user clicks the ButtonForAdditi on, in the Click event for this button you take the Text in the TextboxWithValu e1 and TextboxWithValu e1 and do the calculation.


Since you are doing AutoPostback you will have to put this code in method that handles your TextChanged Event for the textboxes....

eg

Expand|Select|Wrap|Line Numbers
  1. Private void TextboxWithValue1_TextChanged(Object sender, EventArgs e) Handles TextboxWithValue1.TextChanged
  2. {
  3.     //Do your calculations here.
  4.     //Remember, to Get and Set the text from the TextBoxes you use the Text Property
  5.     //Eg:     TextboxWithValue1.Text will return the text in the text box
  6.     //Remember that you do mathematical calculations on data types like Integer, double, float etc...not on Strings.  Therefore you need to convert the text in the textboxes into these type.  If you are using Integers, use Integer.Parse to convert the text, if you're using a Double use Double.Parse...I'm sure you get the idea from this....or you can use Convert as Svinja has suggested in the last post
  7. }
  8.  
  9. Private void TextboxWithValue2_TextChanged(Object sender, EventArgs e) Handles TextboxWithValue2.TextChanged
  10. {
  11.     //Do your calculations here.    
  12. }
  13.  
May 8 '08 #7
Curtis Rutland
3,256 Recognized Expert Specialist
thanks for sending the reply but i m using c# and i wants that i input the number s in the textboxes and the result will be shown in the another textbox . i m using auto post back property for this.please send me solution to this problem
i will be greatly thankful to you.
Auto post back doesn't seem like a good idea. If you want the calculations to be applied in real time (meaning no page refresh) as the user enters the numbers in the boxes you should use Javascript. Remember that ASP.NET is a server side technology. Everything that ASP.NET does requires a page refresh, or an asynchronous update using AJAX. Neither are efficient for what you seem to want to do. Javascript is run client side. No refresh/server update required.
May 9 '08 #8

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

Similar topics

7
10312
by: Amanda | last post by:
Help, I am new to visual basic programming and I was wondering how to allow a textbox to do a calculation by pressing enter ie I want to type the following into a textbox 25.2 * 2 press enter on the keyboard and the textbox to display 50.4 Any Ideas ???????
2
2474
by: DebbieG | last post by:
I have no idea how to start with this one. I have a subform where records could look similar to: Infraction Date Points 01/01/2000 3 06/01/2002 1 Somehow, I've got to calculate the points the driver has as of the current date. For instance, in the above example:
1
349
by: Belee | last post by:
I am doing calculation in a data grid and I get the following error message: "Input format not in correct format". The following is the code in c# private void dgSalesInvoice_CurrentCellChanged(object sender, System.EventArgs e) { decimal result = 0;
1
4659
by: John Mason | last post by:
Hi, I am trying to figure out how to do a client-side calculation based on textbox values, using asp.net, without performing a postback. I have 2 textboxes... <asp:textbox runat="server" CssClass="ddclass" ID="txtTotal" onBlur="calculate()" />
8
4262
by: rdavis7408 | last post by:
I am attempting what I would think would be a simple calculation of the cost of traveling a single mile. But I can not figure this out. The following is my script. Any help would be appreciated. I want the user to enter the price per gallon in one textbox, the miles per gallon in the next textbox and then press the button and get the cost per gallon by dividing the price per gallon by the miles per gallon.
2
3756
by: latufi | last post by:
Hi friends,, I'm new in c programming need your help,, I just do a simple mathematics calculation #include<stdio.h> void main() { int no,x;
10
1701
by: hacorbin | last post by:
I have a VB.NET program I am creating that sums 7 textboxes and displays their total in a total textbox. code: Private Sub btnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd.Click total.text = (Convert.ToInt32(rt1.Text) + Convert.ToInt32(rt2.Text) + Convert.ToInt32(rt3.Text) + Convert.ToInt32(rt4.Text) + Convert.ToInt32(rt5.Text) + Convert.ToInt32(rt6.Text) + Convert.ToInt32(rt7.Text)) What I want...
10
2912
by: nussu | last post by:
Hi , i have 4 textbox's vertically , in that in first 3 textbox's i am entering values in time formati.e in HH:MM:SS .There is no am/pm after time format. for ex : a textbox has to accept only time format as 23:00:00 . Now in textbox4 i need to calculate average of the above 3 textbox's i.e average of 3 textbox's time format whihc is in HH:MM:SS format. once i comeout of 3rd textbox the average of above 3 textbox's has 2 display in...
2
9492
by: Anni V | last post by:
Hi Can some one please help me with the formula to find the EMI from the textbox values txtemiconvamount ddltenure txtemicalcroi to display the EMI amount in the textbox txtemiamount The HTML code is
0
9734
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9607
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10665
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10420
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7681
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6897
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5568
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4358
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3029
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.