Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

  • Leaders
Posted

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. :)

Iceplug, USN

One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(

Posted
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.
  • Leaders
Posted

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.

:)

Iceplug, USN

One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...