Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.    Private Function invoicenum(ByVal trimmedFirstName As String, ByVal lastName As String, ByVal zipcode As String) As String
  2.         'Personal Note on how functions work :
  3.        '  -invoicenum(ByVal trimmedFirstName As String, ByVal lastName As String, ByVal zipcode As String) As String
  4.        '  -is essentially declaring those variables beforehand. In the processOrderButton_Click event, when the function
  5.        '  -is called (invoicenum(trimmedFirstName, lastName, zipcode)), those values could be any name eg. A,B,C and those
  6.        '  -values would be passed through, in order, to trimmedFirstName, lastName, and zipcode.
  7.        '  -The variables in the function are local to the function only, and Return [variables here] is the value of what
  8.        '  -the function is calculating. So [Return trimmedFirstName & lastName & zipcode] is the value of invoicenum, which
  9.        '  -is what gets passed through when called.
  10.  
  11.         trimmedFirstName = trimmedFirstName.Substring(0, 1)
  12.         lastName = lastName.Substring(0, 1)
  13.         zipcode = zipcode.Substring(0)
  14.  
  15.         Return trimmedFirstName & lastName & zipcode
  16.     End Function
  17.     Private Function namefunc(ByVal lname As String, ByVal fname As String) As String
  18.         Return fname & " " & lname
  19.     End Function
  20.     Private Sub processOrderButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles processOrderButton.Click
  21.  
  22.         'This block looks for the comma in the customerName textbox, and returns the position of the comma
  23.        Dim firstlast As String : firstlast = customerName.Text
  24.         Dim commacheckName As String : commacheckName = ","
  25.         Dim commapositionName As Integer = firstlast.IndexOf(commacheckName)
  26.  
  27.         'This block seperates the Last, First names into two seperate variables dependent on the location of the comma.
  28.        'I should note that there is NO ERROR CHECKING, as the directions on the book were very explicit on what input the program
  29.        'is supposed to accept, and anything else is the fault of the user.
  30.        Dim lastName As String : lastName = firstlast.Substring(0, commapositionName)
  31.         Dim firstName As String : firstName = firstlast.Substring(commapositionName + 1)
  32.         'This statement trims the firstname from the left, eliminating the space before the first name directly after the comma.
  33.        Dim trimmedFirstName As String : trimmedFirstName = LTrim(firstName)
  34.  
  35.         'This block does the same thing the above statements did. Now it is looking for the comma in the City, State, Zip
  36.        'text box, and adding six to the value in the substring, which is where the last 4 numbers of the zipcode should be.
  37.        'Again, no error checking. Any messup is the fault of the user.
  38.        Dim citystatezip As String : citystatezip = customerCityStateZip.Text
  39.         Dim commacheckCSZ As String : commacheckCSZ = ","
  40.         Dim commapositionCSZ As Integer = citystatezip.IndexOf(commacheckCSZ)
  41.         Dim zipcode As String : zipcode = citystatezip.Substring(commapositionCSZ + 6)
  42.  
  43.         'This was for early error checking
  44.        'MessageBox.Show(lastName & firstName & zipcode)
  45.  
  46.         Dim sofacost As Single : sofacost = CInt(numSofas.Text) * SOFA
  47.         Dim chaircost As Single : chaircost = CInt(numChairs.Text) * CHAIR
  48.         Dim salestax As Decimal : salestax = CDec(sofacost + chaircost * TAX_RATE)
  49.         Dim totalcost As Decimal : totalcost = CDec(sofacost + chaircost + salestax)
  50.  
  51.  
  52.         invoiceTextBox.Text = "Invoice Number: " & invoicenum(trimmedFirstName, lastName, zipcode) & Environment.NewLine & Environment.NewLine _
  53.            & "Name: " & namefunc(lastName, firstName) & Environment.NewLine & "Address: " & CStr(customerAddress.Text) & Environment.NewLine _
  54.            & "City: " & CStr(customerCityStateZip.Text) & Environment.NewLine & Environment.NewLine & "Number of Chairs: " & CStr(numChairs.Text) _
  55.            & Environment.NewLine & "Number of Sofas: " & CStr(numSofas.Text)
  56.  
  57.  
  58.  
  59.     End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement