Sie sind auf Seite 1von 5

'Project: 'Purpose: 'Created by: 'Modified by: ' ' ' 'Revised by: ' 'Revised by: '

' 'Revised by: ' ' ' 'Revised by: ' calls. ' easier ' Option Explicit On Option Strict On Option Infer Off

maven haven copying service case project - ch 1-2 illustrate creation of interface Cheril Grimmett on 6/26/12 Edwin Mason on 3/18/14 coded exit button, calc button, reset button, set const. set variables, changed Label6 name to totalCopiesLabel changed Label7 name to totalPriceLabel Edwin Mason on 4/12/14 Added choices for color copies, business cards, bindings Edwin Mason on 4/20/2014 Added error-checking to handle non-numeric data entered in text boxes Edwin Mason on 4/21/2014 Set default values of letter/legal pages and copies to zero and changed the reset values to set values to zero instead of empty. Corrects problem if user just wants business cards Edwin Mason on 4/27/2014 Edited code to create Functions. Moved user data conversion/error checking, and calculations to Function To clean up and streamline code, and modualize the program code for editing and readabilty

Public Class mainForm Private Sub exitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exitButton.Click Me.Close() End Sub Private Sub printButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles printButton.Click PrintForm1.PrintAction = Printing.PrintAction.PrintToPreview PrintForm1.Print() End Sub Private Sub calcButton_Click(sender As Object, e As EventArgs) Handles calcButton.Click ' calculates the total number of copies and the total price by calling functions ' for each task 'function to get user data and error check data for textboxes numPagesLetterText.Text = ltrPages() numCopiesLetterText.Text = ltrCopies() numPagesLegalText.Text = lglPages() numCopiesLegalText.Text = lglCopies() 'function for total copies calculation totalCopiesLabel.Text = calcTotalCopies(numPagesLetterText.Text, numCopiesLetterText.Text, numPagesLegalText.Text, numCopiesLegalText.Text) 'function for total color copies if selected colorCopiesLabel.Text = calcTotalColor(numPagesLetterText.Text, numCopiesLetterText.Text, numPagesLegalText.Text,

numCopiesLegalText.Text) 'function for binding calculation bindingLabel.Text = calcBinding() 'function for business card calculation businessCardsLabel.Text = calcCards() ' calculate total price and display results totalPriceLabel.Text = calcTotalOrder() End Sub Private Function ltrPages() As String 'function to assign converted and error checked user entered data in letter pages textbox 'declare variable Dim letters As Integer If IsNumeric(numPagesLetterText.Text) Then letters = CInt(numPagesLetterText.Text) Else letters = verifyInput(numPagesLetterText.Text) numPagesLetterText.Text = letters.ToString End If Return letters.ToString End Function Private Function ltrCopies() As String 'function to assign converted and error checked user entered data in leter copies text box 'declare variable Dim ltrCopy As Integer If IsNumeric(numCopiesLetterText.Text) Then ltrCopy = CInt(numCopiesLetterText.Text) Else ltrCopy = verifyInput(numCopiesLetterText.Text) numCopiesLetterText.Text = ltrCopy.ToString End If Return ltrCopy.ToString End Function Private Function lglPages() As String 'function to assign converted and error checked user entered data in legal pages textbox 'declare variable Dim legals As Integer If IsNumeric(numPagesLegalText.Text) Then legals = CInt(numPagesLegalText.Text) Else legals = verifyInput(numPagesLegalText.Text) numPagesLegalText.Text = legals.ToString End If Return legals.ToString

'error checking function

'error checking function

'error checking function

End Function Private Function lglCopies() As String 'function to assign converted and error checked user entered data in legal copies textbox 'declare variable Dim lglCopy As Integer If IsNumeric(numCopiesLegalText.Text) Then lglCopy = CInt(numCopiesLegalText.Text) Else lglCopy = verifyInput(numCopiesLegalText.Text) numCopiesLegalText.Text = lglCopy.ToString End If Return lglCopy.ToString End Function

'error checking function

Private Function verifyInput(ByVal input As String) As Integer 'function for error checking user data to make sure numeric data is entered While Not IsNumeric(input) input = (InputBox("Input must be numeric: Please re-enter!", "Input Error")) End While Return CInt(input) End Function Private Function calcTotalCopies(ByVal ltPage As String, ByVal ltCopy As String, ByVal lgPage As String, ByVal lgCopy As String) As String 'function to assign calculated total if color not selected 'costs are letter=$0.05, legal=$0.06 'declare variables Dim total As Single = 0 Dim letterPrice As Single = 0.05 Dim legalPrice As Single = 0.06 If colorRadio.Checked = False Then total = ((CSng(ltPage) * CSng(ltCopy)) * letterPrice) + ((CSng(lgPage) * CSng(lgCopy)) * CSng(legalPrice)) colorCopiesLabel.Text = "$0.00" End If Return total.ToString("C2") End Function Private Function calcTotalColor(ByVal ltPage As String, ByVal ltCopy As String, ByVal lgPage As String, ByVal lgCopy As String) As String 'function to assign calculated total color copies to color label if selected 'costs are $0.49 per copy 'declare variables Dim total As Single = 0 Dim colorPrice As Single = 0.49 If colorRadio.Checked = True Then

total = ((CSng(ltPage) * CSng(ltCopy)) * colorPrice) + ((CSng(lgPage) * CSng(lgCopy)) * colorPrice) totalCopiesLabel.Text = "$0.00" End If Return total.ToString("C2") End Function Private Function calcBinding() As String ' function to assign calculated totals for binding based on values from user input ' cost for binding is $1.25 per set 'declare variables Dim binding As Single = 0 Dim bindingPrice As Single = 1.25 If bindingRadio.Checked = True Then Dim numBindings As Single = CSng(InputBox("How may sets need to be bound?", "Binding")) binding = numBindings * bindingPrice End If Return binding.ToString("C2") End Function Private Function calcCards() As String ' function to assign calculated totals for business cards based on values from user input ' to business cards label ' business cards minimum is 100 cards ' costs are a range ' 100 to 149= $65 ' 150 to 200=$55 ' Over 200=$45 'declare variable Dim totalCards As Single = 0 If businessRadio.Checked = True Then Dim numCards As Integer = CInt(InputBox("How many business cards are needed?", "Business Cards")) Select Case numCards Case Is < 100 MessageBox.Show("Minimum order is 100") Case 100 To 149 totalCards = 65 Case 150 To 200 totalCards = 55 Case Is > 200 totalCards = 45 End Select End If Return totalCards.ToString("C2") End Function Private Function calcTotalOrder() As String 'function to assign calculated order total total label

'declare variable Dim total As Single = 0 total total total total += += += += CSng(totalCopiesLabel.Text) CSng(colorCopiesLabel.Text) CSng(bindingLabel.Text) CSng(businessCardsLabel.Text)

Return total.ToString("C2") End Function Private Sub resetButton_Click(sender As Object, e As EventArgs) Handles resetButton.Click ' reset the contents of letter and legal copies boxes to 0 and shift focus back to letter box numPagesLetterText.Text = "0" numCopiesLetterText.Text = "0" numPagesLegalText.Text = "0" numCopiesLegalText.Text = "0" ' reset total boxes totalCopiesLabel.Text = "$0.00" colorCopiesLabel.Text = "$0.00" bindingLabel.Text = "$0.00" businessCardsLabel.Text = "$0.00" totalPriceLabel.Text = "$0.00" ' reset radio buttons bindingRadio.Checked = False businessRadio.Checked = False colorRadio.Checked = False ' set the focus back to first text box numPagesLetterText.Focus() End Sub End Class

Das könnte Ihnen auch gefallen