cs104 F04 lab11 visual basic intro I Make a VB form similar to the "Math" web page in lab 9. The three operations will be Max (same as before), square root (need to use a while-loop for this, explained later) and Lowest Common Multiple (also needs a while loop.) ------ Use radio buttons for Max, Sq Rt and LCM. Whenever a | 12 | X Max number changes (use MouseLeave -- TextChanged will ------ O Sq Rt constantly recompute as you type and cause an error if O LCM you erase everything) the answer box (lower right) ------ should recompute based on the button selected. | 7 | -------- ------ | 12 | When Sq Rt (square root) is selected, the second input -------- box should go away (try the Visible option in Properties and see what code it makes. The box only goes away when you run it.) The rest of this are comments on how you might do this: First, set things up so "Max" starts clicked, and whenever a button is clicked, the 2nd box goes away for Sq Rt or comes back for Max/LCM (Click seems the best event to use here.) Run that and see if it works. Next, we want Textbox1->MouseLeave and Textbox2->MouseLeave to each do the same thing: see if RadioButton1.Checked = true (or #2 or #3,) do the math and stick it in Textbox3. The simplest way to do this is to make a subroutine: Sub domath() End Sub ...and have both MouseLeave events do it: domath() To test this, have the doMath find which button is checked (use ifs) and just put a 1, 2 or 3 in the answer (for the checked button.) Run that to see your ifs are working. Once that is working, fill each in with the right answer. Max can be done with an if (but be sure you compare numbers, 12>5, not "12"<"5") Here is a bash script to find the square root, round up (I used long, descriptive names): %rootroundup 45 rootroundup ----------- testroot=0 trsquared=0 while [ $trsquared -le $1 ] do # if we had 3 and 9, testroot=3 and trsquared=9, this goes to 4 and 16: testroot=$(($testroot+1)) trsquared=$(($testroot * $testroot)) done echo $testroot " is the square root of $1, rounded up" It should count to 7, where it will see 49>45 and stop. In bash, we can print things in the middle of the loop, to check whether it works. In VB with forms, that is more difficult. To find the Least Common Multiple (5 and 6 have LCM 30, 8 and 6 have LCM 24, 2 and 8 have LCM 8) try this "in english" approach: o Call our numbers (to find LCM of) x and y. o Start counting at 1 - if either x or y don't go into your number, add 1 and try again - this will work eventually, since x and y go into x times y. - "Goes into" means that when you divide, there is no remainder. The remainder math symbol in VB is "Mod," as in: 57 Mod 10 (answer is 7) If x Mod num = 0, then num goes into x exactly. - If you need it, not equals in VB is <>