Вы находитесь на странице: 1из 3

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

' 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

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 ' declare constants and variables Const LetterPrice As Single = 0.05 Const LegalPrice As Single = 0.06 Const ColorPrice As Single = 0.49 Const BindingPrice As Single = 1.25 Dim letterPages As Integer = 0 Dim letterCopies As Integer = 0 Dim legalPages As Integer = 0 Dim legalCopies As Integer = 0 Dim totalPrice As Single = 0 Dim totalCopies As Single = 0 Dim totalColor As Single = 0 Dim totalBinding As Single = 0 Dim totalCards As Single = 0 ' Loops to error check and correct non-numeric data entered by user While Not IsNumeric(numPagesLetterText.Text) numPagesLetterText.Text = InputBox("Input must be numeric: Please re-enter!", "Input Error") End While While Not IsNumeric(numCopiesLetterText.Text) numCopiesLetterText.Text = InputBox("Input must be numeric: Please reenter!", "Input Error") End While

While Not IsNumeric(numPagesLegalText.Text) numPagesLegalText.Text = InputBox("Input must be numeric: Please re-enter!", "Input Error") End While While Not IsNumeric(numCopiesLegalText.Text) numCopiesLegalText.Text = InputBox("Input must be numeric: Please re-enter!", "Input Error") End While ' store user input as variable Integer.TryParse(numPagesLetterText.Text, letterPages) Integer.TryParse(numCopiesLetterText.Text, letterCopies) Integer.TryParse(numPagesLegalText.Text, legalPages) Integer.TryParse(numCopiesLegalText.Text, legalCopies) ' calculate total copies or color copies if selected, (costs are letter=$0.05, legal=$0.06, color=$0.49 per copy) If colorRadio.Checked = True Then totalColor = ((letterPages * letterCopies) * ColorPrice) + ((legalPages * legalCopies) * ColorPrice) colorCopiesLabel.Text = totalColor.ToString("C2") totalCopiesLabel.Text = "$0.00" Else totalCopies = ((letterPages * letterCopies) * LetterPrice) + ((legalPages * legalCopies) * LegalPrice) totalCopiesLabel.Text = totalCopies.ToString("C2") colorCopiesLabel.Text = "$0.00" End If ' calculate totals for binding based on values from user input, (cost for binding is $1.25 per set) If bindingRadio.Checked = True Then Dim numBindings As Single = CSng(InputBox("How may sets need to be bound?", "Binding")) totalBinding = numBindings * BindingPrice bindingLabel.Text = totalBinding.ToString("C2") Else bindingLabel.Text = "$0.00" End If ' calculate totals for business cards based on values from user input ' business cards minimum is 100 cards ' costs are a range ' 100 to 149= $65 ' 150 to 200=$55 ' Over 200=$45 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 businessCardsLabel.Text = totalCards.ToString("C2") Else businessCardsLabel.Text = "$0.00" End If ' calculate total price and display results totalPrice = totalCopies + totalColor + totalBinding + totalCards totalPriceLabel.Text = totalPrice.ToString("C2") End Sub Private Sub resetButton_Click(sender As Object, e As EventArgs) Handles resetButton.Click ' clear the contents of letter and legal copies boxes and shift focus back to letter box numPagesLetterText.Text = String.Empty numCopiesLetterText.Text = String.Empty numPagesLegalText.Text = String.Empty numCopiesLegalText.Text = String.Empty ' 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

Вам также может понравиться