labs 6 and 7. adding “controls” to a document properties
Post on 22-Dec-2015
226 views
TRANSCRIPT
Labs 6 and 7
Adding “Controls” to a Document
Properties
Code!Celsius: TextBox2.Text = (TextBox1.Text - 32) * (5 / 9)Fahrenheit: TextBox2.Text = (TextBox1.Text) * (9 / 5) + 32Squared: TextBox2.Text = (TextBox1.Text) ^ 2Square Root: TextBox2.Text = Sqr(TextBox1.Text)Random (Lab 7): TextBox2.Text = Rnd( )
Better
If IsNumeric(TextBox1.Text) Then TextBox2.Text = (TextBox1.Text - 32) * (5 / 9)Else TextBox2.Text = "Not a number"End If
Square Root – two IFsIf 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
Random NumbersRnd ( ) gives a random floating point number
between 0 and 1
Int ( ) converts a floating point number to an integer by truncating the whole part1.5672 becomes 1
Int( 2 * Rnd( ) ) will give us random 0s and 1s
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
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% 0sIf it’s not, then tragedy looms
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