BU 3015w Visual Basic (Midterm Dr. A. Ebrahimi Winter 06)

 

Do the question 2-4 in the Lab tonight and submit it. Submit the Question 1 and 5 by the end of Tuesday night.

use ctrl+alt+Prinscr to copy your steps and paste it to a word document. Mail the word document to ebrahimidr@gmail.com

 

 

To answer the questions, work with the Visual Basic .Net environment and paste all of your answers (forms and code) into a Word document to print out. (Use Alt + Print Screen to copy forms when program is running)

 

To receive complete points answer each part separately.

Q1a)What is wrong with the following average program?  (hint 9999 is a sentinel value.
dim x as integer
dim count as integer
dim avg as single
sum= 0
count=1
while x<>9999
x=inputbox("ENTER A NUMBER")
sum=sum+x
count = count + 1
end while
if count > = 0 then
 avg = sum / count
else
msgbox (" ERROR IN COUNT " )
endif

 

Q1b) Fix the above problem and run the program


Q1c) What is wrong with the following search program?

dim id( ) as integer ={1234, 4567,8901,2468,1357,9764}

dim i,key as integer
for i=1 to id.length-1
key=inputbox("ENTER THE SEARCH KEY")
if  (key=id(i) then
 msgbox ("ID FOUND IN LOCATION" & i)
else
msgbox(" ID IS NOT LISTED")
end if
next

Q1d) Fix the above problem and run the program.

 

Q2a)Design a form called Dr Ebrahimi payroll (instead put your own name). The form has three textbox labeled as EMPLOYEE’S ID, HOURS WORKED and HOURLY RATE. A button known as COMPUE GROSS PAY will compute the gross pay for the employee. The output will be display in a textbox labeled as GROSS PAY.

 

Q2b) Expand the above program to compute the employee’s tax amount. An input text box labeled as TAX RATE is to enter the tax rate for example (The default tax rate will be set in property to 0.30 for 30%). A button known as COMPUTE TAX AMOUNT will figure out the employee’s tax amount. The output will display in a text box labeled as TAX AMOUNT.

Extra credit- Instead of compute button use text4.textchanged(  ) to compute the tax amount.

 

Q2c) Expand the above program to compute the net pay. A button known as COMPUTE NET PAY will compute the net pay. The output will be display in a text box labeled as NET PAY. 

Extra credit- instead of text box numbering such as textbox1.text use a proper name in the properties such as empid.text.

 

Q3A)Expand the above program to repeat for 5 employees. Declares all variables used in the program. Assign each input variable by inputbox (“PLEASE ENTER EMPLOYEE’S ID”). Assign value of each input variable to the respective text box. Similarly assign value of each output 

Variable to the respective text box. Only use one command button captioned as COMPUTE 5 EMPLOYEE.

Q3b) Display the employee counter by a msgbox at the end of each round in the loop or assign the value of the counter variable to a textbox labeled as COUNTER.

 

Q3c) loop the number of employees interactively by an inputbox. Assign the input value of the input box as a number of the employees. The program will loop depends on the entered value (6 or 10).

Extra credit- program should loop until a sentinel value is entered.

 Q3d) Expand the program to take all the data from the input file called employee.txt

 

Q4a) Modify the above program to use a variable tax rate. Assign the tax rate based on the computed gross pay. Tax rate for gross pay more than $500.00 is 20%, for more than $300.00 is 15%, and 10% for the rest. You can use the following:

 

If ………….Then

                                                          ………….

ElseIf ……. Then

………….

                                                Else

                                                          ………….

End If

 

 

 

Q4b)  Include marital status (Single, Married) as input to your form. You can use a TextBox or RadioButton, etc. For Single employees, additional 10% will be added to the tax rate.  For Married employees, 5% will be subtracted from tax rate.

 

         

Q4c) Error-checking: Use If … Then statements to check for errors on two of the TextBoxes such as hours worked, hourly rate, or gross pay (e.g. hours worked must be greater than 0 and less than 56, and gross pay must be greater than zero, etc.).

 

For example:

 

For hours worked greater than 56, you can display an error message such as MsgBox(“Please enter correct hours worked.”)

 

 

Q5a) Run the following program. Briefly say in your own words what does it do?

 

Create a new project and use your name in the project title, save it on your F: drive (your account). Create a text file called employees.txt and save it desktop or in the “bin” folder of your project. Enter data into your text file including the name and gross pay of employees in the following format:

Andres

1000.00

John

500.00

Lina

750.00

Peter

456.00

Anna

670.00

 

 

 

 

 

 

 

 

 

 

 

Create a form similar to:

 

 

Double-click on the button to write the code:

 

  Dim name As String

        Dim grosspay As Double

        Dim i As Integer

 

        Dim fin As IO.StreamReader = IO.File.OpenText("employees.txt")

 

        For i = 1 To 5

 

            name = fin.ReadLine

            grosspay = fin.ReadLine

 

            If name = TextBox1.Text Then

                TextBox2.Text = FormatCurrency(grosspay)

            End If

 

        Next

 

5b)Explain what this program does and how it works (e.g. what does the loop do, what does the If … Then statement do)

 

 

How to create a text file and write to a file  

dim fout as Io.streamWriter = Io.File.CreateText("employee2.txt)

fout.writeline(textbox1.text)

fout.writeline(textbox2.text)

fout.close