+ All Categories
Home > Documents > Labs 6 and 7. Adding “Controls” to a Document Properties.

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

Date post: 22-Dec-2015
Category:
View: 224 times
Download: 2 times
Share this document with a friend
Popular Tags:
12
Labs 6 and 7
Transcript
Page 1: Labs 6 and 7. Adding “Controls” to a Document Properties.

Labs 6 and 7

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

Adding “Controls” to a Document

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

Properties

Page 4: Labs 6 and 7. Adding “Controls” to a Document Properties.
Page 5: 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( )

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

Better

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

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

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

Page 8: Labs 6 and 7. Adding “Controls” to a Document Properties.
Page 9: Labs 6 and 7. Adding “Controls” to a Document Properties.

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

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

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

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

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

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

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


Recommended