teamdad Posted April 4, 2004 Posted April 4, 2004 If this is an easy question please excuse me. I am new to VB.NET and have made a few small programs that randomize numbers but I want to learn some math now and need a working code example. I want to have a series of text boxes 1 thru 10. The math formula I need help with is below. If it's easy enough I would like the calculations to occur when the numbers are typed in the text boxes by the user like an on change event. If it's easier to use a button to do all the caluclations after the numbers have been entered in the text boxes that would be ok too. textbox1 minus textbox2 plus textbox3 = textbox4 textbox4 minus textbox5 plus textbox6 = textbox7 textbox7 minus textbox8 plus textbox9 = textbox10 Thanks for help with this. Quote
Leaders Iceplug Posted April 4, 2004 Leaders Posted April 4, 2004 Are you going to allow the user to type in TextBoxes 4, 7, and/or 10? If so, then that might make things a bit hazy... since you are putting a result into TextBox4... and then you are using the result of TextBox4 to compute the result of TextBox7. I suppose you could just use the TextChanged event of the appropriate textbox to calculate the result. e.g. In TextBox 1, 2, and 3's TextChanged event, recalculate TextBox4.Text To do this: TextBox4.Text = (Integer.Parse(TextBox1.Text) - Integer.Parse(TextBox2.Text) + Integer.Parse(TextBox3.Text).ToString("G"). Where Integer.Parse turns the string text into a number that can be added and subtracted... ToString turns the result back into a string using General number formatting. :) Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
teamdad Posted April 4, 2004 Author Posted April 4, 2004 users would only be able to type "change" the numbers in textbox1, textbox2, textbox3, textbox5, textbox6, textbox8 and textbox9 only. Text boxes 4, 7 and 10 are for showing the answer to the equasion. Quote
Leaders Iceplug Posted April 4, 2004 Leaders Posted April 4, 2004 OK... well... TB4 = TB1 - TB2 + TB3 (eq. 1) TB7 = TB4 - TB5 + TB6 You can make a shortcut and say: TB7 = (TB1 - TB2 + TB3) - TB5 + TB6 (eq. 2) TB10 = TB7 - TB8 + TB9 Again another shortcut: TB10 = (TB1 - TB2 + TB3 - TB5 + TB6) - TB8 + TB9 (eq. 3) So, TB4 depends on the first three textboxes, so Equation 1 can go into the TextBox1, 2, and 3's TextChanged event. TB7 depends on 1, 2, 3, 5, and 6, so eq. 2 can go into those 5 boxes. TB10 depends on 1, 2, 3, 5, 6, 8, and 9... so eq. 3 can go into those 7 textboxes. :) Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.