Docsity

Experiment with Calling Predefined Math Functions | IST 256, Lab Reports of Information Technology

Toggle sidebar
bg1
IST 256
Lab 14 – March 5, 2008
1. Experiments with calling Predefined Functions
Open a new project in Visual Studio and call it something like TestFunctions.
Make one set of a Label, TextBox, Button and ResultLabel to test math functions, and
another set to test string functions. Your form can look something like:
Type a Number: |_________| |TestMath| Result:
Type a String: |_________| |TestString| Result:
Math Functions
In the Form program for the TestMath button, you are going to put several calls to math
functions from the Predefined Functions sheet, one at a time.
First, declare a variable named number as a Single and assign it the number from the
number TextBox.
a. Math.Round:
Add a declaration of a Single variable and call Math.Round with number. Show the
result:
Example of the program: (you may need to change textbox and label names)
Dim number as Single
Dim rounded as Single
number = CSng(TextBox1.Text)
rounded = Math.Round(number)
Label2.Text = “Result: “ & CStr(rounded)
Test this with at least three (3) values and record the tests here, by writing the numbers
you typed in and the results in the following space. Be sure to test values with decimal
points and at least one negative number. Also one of the decimal fractions should be
under .5 and one should be over .5.
pf3

Partial preview of the text

Download Experiment with Calling Predefined Math Functions | IST 256 and more Lab Reports Information Technology in PDF only on Docsity!

IST 256

Lab 14 – March 5, 2008

1. Experiments with calling Predefined Functions

Open a new project in Visual Studio and call it something like TestFunctions.

Make one set of a Label, TextBox, Button and ResultLabel to test math functions, and another set to test string functions. Your form can look something like:

Type a Number: |_________| |TestMath| Result:

Type a String: |_________| |TestString| Result:

Math Functions In the Form program for the TestMath button, you are going to put several calls to math functions from the Predefined Functions sheet, one at a time.

First, declare a variable named number as a Single and assign it the number from the number TextBox.

a. Math.Round: Add a declaration of a Single variable and call Math.Round with number. Show the result: Example of the program: (you may need to change textbox and label names) Dim number as Single Dim rounded as Single number = CSng(TextBox1.Text) rounded = Math.Round(number) Label2.Text = “Result: “ & CStr(rounded)

Test this with at least three (3) values and record the tests here, by writing the numbers you typed in and the results in the following space. Be sure to test values with decimal points and at least one negative number. Also one of the decimal fractions should be under .5 and one should be over .5.

b. Math.Ceiling: Keep the declaration of number and the statement that assigns to it from the TextBox and remove the other declaration and statement. Declare an integer variable. Assign the integer variable to get the result of calling Math.Ceiling(number). Test this version of the program with at least three values, including one negative number and write the results here:

c. Choose one of the other Math functions, Math.Sqrt or Math.Abs. Declare a variable to hold the result (what type should it be?), call the function and show the result. Test it with at least three values and write the results here:

String Functions: Now we will do a similar set of tests for String functions, using the String TextBox, Button and Result Label.

For all the tests, declare a variable called text of type String and assign it the value of the String TextBox.

a. StrReverse In the code for the String button, add a declaration for another String variable and add a call to StrReverse and show the result. Example: (you may need to change textbox and label names) Dim text as String Dim reversed as String text = TextBox2.Text reverseded = StrReverse(text) Label4.Text = “Result: “ & reversed

Test this program with at least two (2) different strings and write the results of your tests here: