Presentation is loading. Please wait.

Presentation is loading. Please wait.

Labs 6 and 7. Adding “Controls” to a Document Properties.

Similar presentations


Presentation on theme: "Labs 6 and 7. Adding “Controls” to a Document Properties."— Presentation transcript:

1 Labs 6 and 7

2 Adding “Controls” to a Document

3 Properties

4

5 Code! Celsius: TextBox2.Text = (TextBox1.Text - 32) * (5 / 9) Fahrenheit: TextBox2.Text = (TextBox1.Text) * (9 / 5) + 32 Squared: TextBox2.Text = (TextBox1.Text) ^ 2 Square Root: TextBox2.Text = Sqr(TextBox1.Text) Random (Lab 7): TextBox2.Text = Rnd( )

6 Better If IsNumeric(TextBox1.Text) Then TextBox2.Text = (TextBox1.Text - 32) * (5 / 9) Else TextBox2.Text = "Not a number" End If

7 Square Root – two IFs If IsNumeric(TextBox1.Text) Then If (TextBox1.Text >= 0) Then TextBox2.Text = Sqr(TextBox1.Text) Else TextBox2.Text = "Must be positive" End If Else TextBox2.Text = "Not a number" End If

8

9 Random Numbers Rnd ( ) gives a random floating point number between 0 and 1 Int ( ) converts a floating point number to an integer by truncating the whole part 1.5672 becomes 1 Int( 2 * Rnd( ) ) will give us random 0s and 1s

10 The Princeton Egg Project http://www.redorbit.com/news/science/126649 /can_this_black_box_see_into_the_future/ http://noosphere.princeton.edu/tapestry.html

11 What does that mean for us If you flip a coin (1= heads, 0 = tails) 1000 times, The results should always be very close to 50% 1s and 50% 0s If it’s not, then tragedy looms

12 If IsNumeric(TextBox1.Text) Then If (TextBox1.Text >= 0) Then TextBox2.Text = 0 X = 0 While ( X < Int(TextBox1.Text) ) TextBox2.Text = Int(2 * Rnd()) + Int(TextBox2.Text) X = X + 1 Wend Else TextBox2.Text = "Must be positive" End If Else TextBox2.Text = "Not a number" End If


Download ppt "Labs 6 and 7. Adding “Controls” to a Document Properties."

Similar presentations


Ads by Google