Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Private Function invoicenum(ByVal trimmedFirstName As String, ByVal lastName As String, ByVal zipcode As String) As String
- 'Personal Note on how functions work :
- ' -invoicenum(ByVal trimmedFirstName As String, ByVal lastName As String, ByVal zipcode As String) As String
- ' -is essentially declaring those variables beforehand. In the processOrderButton_Click event, when the function
- ' -is called (invoicenum(trimmedFirstName, lastName, zipcode)), those values could be any name eg. A,B,C and those
- ' -values would be passed through, in order, to trimmedFirstName, lastName, and zipcode.
- ' -The variables in the function are local to the function only, and Return [variables here] is the value of what
- ' -the function is calculating. So [Return trimmedFirstName & lastName & zipcode] is the value of invoicenum, which
- ' -is what gets passed through when called.
- trimmedFirstName = trimmedFirstName.Substring(0, 1)
- lastName = lastName.Substring(0, 1)
- zipcode = zipcode.Substring(0)
- Return trimmedFirstName & lastName & zipcode
- End Function
- Private Function namefunc(ByVal lname As String, ByVal fname As String) As String
- Return fname & " " & lname
- End Function
- Private Sub processOrderButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles processOrderButton.Click
- 'This block looks for the comma in the customerName textbox, and returns the position of the comma
- Dim firstlast As String : firstlast = customerName.Text
- Dim commacheckName As String : commacheckName = ","
- Dim commapositionName As Integer = firstlast.IndexOf(commacheckName)
- 'This block seperates the Last, First names into two seperate variables dependent on the location of the comma.
- 'I should note that there is NO ERROR CHECKING, as the directions on the book were very explicit on what input the program
- 'is supposed to accept, and anything else is the fault of the user.
- Dim lastName As String : lastName = firstlast.Substring(0, commapositionName)
- Dim firstName As String : firstName = firstlast.Substring(commapositionName + 1)
- 'This statement trims the firstname from the left, eliminating the space before the first name directly after the comma.
- Dim trimmedFirstName As String : trimmedFirstName = LTrim(firstName)
- 'This block does the same thing the above statements did. Now it is looking for the comma in the City, State, Zip
- 'text box, and adding six to the value in the substring, which is where the last 4 numbers of the zipcode should be.
- 'Again, no error checking. Any messup is the fault of the user.
- Dim citystatezip As String : citystatezip = customerCityStateZip.Text
- Dim commacheckCSZ As String : commacheckCSZ = ","
- Dim commapositionCSZ As Integer = citystatezip.IndexOf(commacheckCSZ)
- Dim zipcode As String : zipcode = citystatezip.Substring(commapositionCSZ + 6)
- 'This was for early error checking
- 'MessageBox.Show(lastName & firstName & zipcode)
- Dim sofacost As Single : sofacost = CInt(numSofas.Text) * SOFA
- Dim chaircost As Single : chaircost = CInt(numChairs.Text) * CHAIR
- Dim salestax As Decimal : salestax = CDec(sofacost + chaircost * TAX_RATE)
- Dim totalcost As Decimal : totalcost = CDec(sofacost + chaircost + salestax)
- invoiceTextBox.Text = "Invoice Number: " & invoicenum(trimmedFirstName, lastName, zipcode) & Environment.NewLine & Environment.NewLine _
- & "Name: " & namefunc(lastName, firstName) & Environment.NewLine & "Address: " & CStr(customerAddress.Text) & Environment.NewLine _
- & "City: " & CStr(customerCityStateZip.Text) & Environment.NewLine & Environment.NewLine & "Number of Chairs: " & CStr(numChairs.Text) _
- & Environment.NewLine & "Number of Sofas: " & CStr(numSofas.Text)
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement