Class Notes
6/7/06
Today’s Menu:
Chapter 3
* Loop (go over and over)
2.a grosspay
2.b netpay
Version of your payroll program.
|
Version 1. 1. Interactive – using inputbox and msgbox.
|
Version 2.
* Extra-credit |
Version 3.
form1.load use command button.click. * Extra-credit |
Note: Specification is very important in programming and you need to follow the specification.
LOOP AS LABOR FORCE
One of the strengths of the computer is its ability to repeat a process over and over without getting tired of threatening to strike. The program that you have written to perform a single task can now be repeated to perform the same task as many times as you wish. This process of going over and over is known as repetition and is called a loop. Can you think of a loop? Of course! Our everyday activities, including getting up, eating, working, studying and sleeping are examples of a loop. Can you identify other loops?
COMPUTERS IN THE LOOP
Did you know that your computer is in a constant cycle of input, process, and output? This constant cycle of input, processing and output means that your computer is in a loop. It waits for you to enter data, takes your input, analyzes it, performs the required task, and finally displays the result. We can generalize and say that every automated system, from the bank ATM machine, supermarket pricing, through the search engine of the internet all use the loop.
Example of while loop.
Want to run while 5 times then end it with end while.
While (5)
Id = inputbox (“Enter ID”)
Msgbox(“Your ID is ” & ID)
End while
If you don’t want to use msgbox bye bye. The we will use brasses
Msgbox(“BYE BYE”)
Conclusion:
While loop has a condition, if condition is true, loop will execute, if it’s
false, loop won’t execute.
Example: 2>5 (False) , 2>3 (False), 3>2 (True)
Make a conditional loop.

See examples on page (57)
Version 1: counter = 5, while (counter)
Dim counter As Integer
counter =5
while (counter)
msgbox(“I LIKE YOU”)
counter = counter -1
end while
msgbox(“BYE BYE LOVE”)
NOTE: This program executes 5 times displaying the message “I LOVE YOU”, then it
displays the message “BYE BYE LOVE”

Version 2: counter = 5, while (counter > 0)
Dim counter As Integer
counter = 5
While (counter > 0)
MsgBox("I LIKE YOU")
counter = counter - 1
End While
MsgBox("BYE BYE LOVE")

This program does the same thing, but in another way.
Version 3: same example with counter = 0
Dim counter As Integer
counter = 0
While (counter < 5)
MsgBox("I LIKE YOU")
counter = counter + 1
End While
MsgBox("BYE BYE LOVE")

Assignment on page 89, code on page 61
3a) Expand your Payroll program so that interactively repeats for 5 employees.
Dim employeeid, hoursworked, counter As Integer
Dim hourlyrate, grosspay As Double
counter = 5
While (counter = 5)
employeeid = InputBox("ENTER ITEM ID")
hoursworked = InputBox("ENTER HOURS WORKED")
hourlyrate = InputBox("ENTER HOURLY RATE")
grosspay = hoursworked * hourlyrate
MsgBox("EMPLOYEE ID IS " & employeeid)
MsgBox("YOUR GROSS PAY IS " & grosspay)
counter = counter - 1
End While
MsgBox("BYE BYE")
Another version using textbox
IT ONLY DISPLAYS THE LAST DATA ENTERED
Dim employeeid, hoursworked, counter As Integer
Dim hourlyrate, grosspay, taxamount, netpay As Double
counter = 5
While (counter)
employeeid = InputBox("ENTER ITEM ID")
hoursworked = InputBox("ENTER HOURS WORKED")
hourlyrate = InputBox("ENTER HOURLY RATE")
textbox1.text = employeeid
textbox2.text = hoursworked
TextBox3.Text = hourlyrate
grosspay = hoursworked * hourlyrate
textbox4.text = grosspay
counter = counter - 1
End While
MsgBox("BYE BYE")
Version 3 OF CHAP 2. NOT USING LOOP BUT USING BUTTONS AND TXTBOX
By typing
TextBox1.Text = " " we assign a blank value to the textbox
Dim employeeid, hoursworked As Integer
Dim hourlyrate, grosspay As Double
employeeid = TextBox1.Text
hoursworked = TextBox2.Text
hourlyrate = TextBox3.Text
grosspay = hoursworked * hourlyrate
TextBox4.Text = grosspay
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
TextBox1.Text = " "
TextBox2.Text = " "
TextBox3.Text = " "
TextBox4.Text = " "
