Application Programming for Information Systems - Lab Assignment 8 | IST 256, Lab Reports of Information Technology

Material Type: Lab; Class: Application Programming for Information Systems; Subject: Information Studies; University: Syracuse University; Term: Fall 2008;

Typology: Lab Reports

Pre 2010

Uploaded on 08/09/2009

koofers-user-05r-1
koofers-user-05r-1 🇺🇸

10 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
IST 256
Lab Week 8, Part 2 (really) – Wednesday, October 15, 2008
1. Understanding Procedures with ByRef parameters
Assume that there is a Form for an application that has one TextBox where the user types
in a sales total and one label where the amount of tax is shown for that total. There is
also the following definition of a general procedure and a button function that calls the
procedure:
' Procedure to compute tax amount from the total (of a sales)
Private Sub ComputeTax(ByRef tb As TextBox, ByRef taxamount As Single)
' Tax rate is fixed at 8%
Dim taxrate as Single
taxrate = 0.08
taxamount = CSng(tb.Text) * taxrate
End Function
' User gives the total sales bought in a textbox,
' Compute the amount of tax and Display in a label
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim result as Single
Call ComputeTax(TextBox1, result)
' Show the result
Label1.Text = "Resulting Tax = " & Format(result, "currency")
End Sub
Suppose that the user types the number “100” in the textbox. What will be displayed in
Label1.Text? Write your answer here.
Suppose that the user types the number “3” in the textbox. What will be displayed in
Label1.Text? Write your answer here.
pf3
pf4

Partial preview of the text

Download Application Programming for Information Systems - Lab Assignment 8 | IST 256 and more Lab Reports Information Technology in PDF only on Docsity!

IST 256

Lab Week 8, Part 2 (really) – Wednesday, October 15, 2008

1. Understanding Procedures with ByRef parameters

Assume that there is a Form for an application that has one TextBox where the user types

in a sales total and one label where the amount of tax is shown for that total. There is

also the following definition of a general procedure and a button function that calls the

procedure:

' Procedure to compute tax amount from the total (of a sales) Private Sub ComputeTax(ByRef tb As TextBox, ByRef taxamount As Single) ' Tax rate is fixed at 8% Dim taxrate as Single taxrate = 0. taxamount = CSng(tb.Text) * taxrate End Function

' User gives the total sales bought in a textbox, ' Compute the amount of tax and Display in a label Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim result as Single

Call ComputeTax(TextBox1, result)

' Show the result Label1.Text = "Resulting Tax = " & Format(result, "currency") End Sub

Suppose that the user types the number “100” in the textbox. What will be displayed in

Label1.Text? Write your answer here.

Suppose that the user types the number “3” in the textbox. What will be displayed in

Label1.Text? Write your answer here.

2. Testing Predefined Functions

In this lab, you will write a small program to test how some of the predefined functions

work. There will be parts to the program, one to test Math functions and one to test

String functions. In the test program, you will test one function at a time, and keep

changing the program to test another function.

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. InStr

Keep the code that declares text as a String and assigns it the value of the TextBox.

Declare an integer variable, suppose it is named index

Assign it the result of a call to InStr with the text and another string to find,

but just use a single character for the find string. For example:

index = InStr(text, “c”)

Write down which letter you used as a find string and test this on at least three strings and

show the results. Be sure to pick example that contains the letter and at least one

example that does not.

c. Choose another String function from LCase, UCase, Len, and Trim. Declare a

variable to get the result of the function (what type should it be?), call the function and

show the result. Test with at least three example strings and write the results here. Be

sure to state which function you are testing.

For this week’s lab, hand in the lab page from Monday, the program from Monday

and this lab page from Wednesday, and the TestFunctions program as it ended up.