Public Class Form1
'Const 115 sq/ft of wall space is one gallon of paint.
Const sngSQF As Single = 115S
'Salary of labor per hour.
Const decSalary As Decimal = 18.0
'Const 8 hours of labor required per gallon of paint.
Const intHours As Integer = 8
Dim sngTotalArea As Single = 0
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
'Prevents nothing being entered on the lables.
If IsNumeric(txtRooms.Text) = False Or IsNumeric(txtPaintPrice.Text) = False Then
MessageBox.Show("Please enter a integer. No text is allowed.", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return
End If
'Disallows anything below $10 for paint price
Dim decPaintPrice As Decimal
decPaintPrice = CDec(txtPaintPrice.Text)
If decPaintPrice < 10 Then
MessageBox.Show("Minimum price for paint is $10.00.", "Price Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return
End If
'Prevents anything below one for number of rooms.
Dim intRooms As Decimal
intRooms = CInt(txtRooms.Text)
GetTotalArea()
'Calculates the amount of paint needed to perform the job.
lblPaintGallons.Text = FormatNumber(sngTotalArea / sngSQF, 0)
Dim decPaintGallons As Decimal
decPaintGallons = CDec(lblPaintGallons.Text)
Dim decTotalPaintCost As Decimal
'Calculates the total cost of paint.
decTotalPaintCost = CDec(decPaintGallons * decPaintPrice)
lblTotalPaintCost.Text = FormatCurrency(decTotalPaintCost)
LaborHours()
'Calculates the total cost of labor.
Dim sngLaborHours As Single
sngLaborHours = CSng(lblLaborHours.Text)
Dim decTotalLaborCost As Decimal
decTotalLaborCost = CDec(sngLaborHours * decSalary)
lblTotalLaborCost.Text = FormatCurrency(decTotalLaborCost)
'Calculates the total cost.
Dim decTotal As Decimal
decTotal = CDec(decTotalLaborCost + decTotalPaintCost)
lblTotal.Text = FormatCurrency(decTotal)
End Sub
Function GetTotalArea()
'This function is to add the area of each room.
sngTotalArea = 0
Dim decArea As Decimal 'To hold the area.
Dim intRooms As Integer = 1 'Number of rooms needed to be painted
Dim intCount As Integer = 1 'Loop Count
Dim strInput As String 'To get the area input
intRooms = CInt(txtRooms.Text)
If intRooms < 1 Then
MessageBox.Show("Enter positive numbers for number of rooms. Thank you.", "Error Room", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Function
End If
' Following loop gets the area of each room.
Do While intCount <= intRooms
strInput = InputBox("Enter the area of room " & intCount.ToString, "Input Needed")
If strInput <> "" Then
decArea = CInt(strInput)
sngTotalArea += decArea
intCount += 1
End If
Loop
Return sngTotalArea
End Function
Function LaborHours()
Dim sngPaintGallons As Single
sngPaintGallons = CSng(lblPaintGallons.Text)
lblLaborHours.Text = FormatNumber(sngPaintGallons * intHours, 0)
Return lblLaborHours.Text
End Function
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
' This reset the controls to default values.
ResetEntries()
ResetPrice()
'Prevents a running total
sngTotalArea = 0
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
' End the application
Me.Close()
End Sub
Sub ResetEntries()
'This resets entries in the form.
txtRooms.Text = String.Empty
txtPaintPrice.Text = String.Empty
End Sub
Sub ResetPrice()
' Reset lables.
lblPaintGallons.Text = String.Empty
lblLaborHours.Text = String.Empty
lblTotalPaintCost.Text = String.Empty
lblTotalLaborCost.Text = String.Empty
lblTotal.Text = String.Empty
End Sub
End Class