|
-
Apr 15th, 2011, 06:08 PM
#1
Thread Starter
New Member
String manipulation!
I'm doing some homework for my VB class where I have to write a program that creates an invoice for a customer. I'm having an issue with converting the name input from the format of (Last, First) within the same textbox to (First Last) in a listbox via a function. I have done everything but dealing with the strings and I'm at a loss.
I'm also having to create an invoice number with the first two letters of the last name and also the last four numbers of the zip code in an address line such as
City, State, Zip.
Manipulating these strings is killing me.
Below is the code that I have written, manipulation of the strings must be in one function for each the invoice and the and the name issue....
Can anyone give some suggestions????
Public Class question3
Dim custinvoicenum As String
Private Sub btnProcess_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnProcess.Click
Dim custname As String 'Name of customer
Dim custaddress As String 'customer's address
Dim custcitystzip As String 'customer's city state and zipcode
Dim orderedchairs As Integer 'number of chairs ordered by customer
Dim orderedsofas As Integer 'number of sofas ordered by customer
Dim custinvoicenum As String 'customer's invoice number
Dim costoutput As Double 'cost before taxes
Dim salestax As Double 'total amount of taxes paid
Dim totalcost As Double 'total amount paid after taxes are added
Dim taxrate As Double 'taxrate charged to cost before taxes
Dim cname As String
'tasks
InputData(custname, custaddress, custcitystzip, orderedchairs, orderedsofas) 'task 0
costoutput = cost_output(orderedchairs, orderedsofas) 'task 1
salestax = sales_tax(costoutput, taxrate) 'task 2
totalcost = total_cost(salestax, costoutput) 'task 3
showtotal(custname, custaddress, custcitystzip, orderedchairs, orderedsofas, costoutput, salestax, totalcost) 'task 4
custinvoicenum = invoice_number(custname, custcitystzip) 'task 5
custname = cust_name(custname) 'task 6
End Sub
Sub InputData(ByRef custname As String, ByRef custaddress As String, ByRef custcitystzip As String, ByRef orderedchairs As Integer,
ByRef orderedsofas As Integer)
'Task 0 InputData
custname = CStr(txtboxName.Text)
custaddress = CStr(txtboxAddress.Text)
custcitystzip = CStr(txtboxCityStateZip.Text)
orderedchairs = CInt(txtboxChairs.Text)
orderedsofas = CInt(txtboxSofas.Text)
End Sub
Function cost_output(ByVal orderedchairs As Integer, ByVal orderedsofas As Integer) As Double
'Task 1: Compute cost before taxes
Return ((orderedchairs * 350) + (orderedsofas * 925))
End Function
Function sales_tax(ByVal costoutput As Double, ByVal taxrate As Double)
'Task 2: Compute total sales tax
taxrate = 0.05
Return (taxrate * costoutput)
End Function
Function total_cost(ByVal salestax As Double, ByVal costoutput As Double)
'Task 3: Compute total cost to be billed to customer
Return (salestax + costoutput)
End Function
Function invoice_number(ByVal custname As String, ByVal custcitystzip As String)
'Task 5: Invoice number generation
Return (custname.Substring(0, 2) & Right.ToString(custcitystzip))
End Function
Function cust_name(ByVal custname As String) As String
End Function
Sub showtotal(ByVal custname As String, ByVal custaddress As String, ByVal custcitystzip As String, ByVal orderedchairs As Integer,
ByVal orderedsofas As Integer, ByVal costoutput As Double, ByVal salestax As Double, ByVal totalcost As Double)
'Task 4 Display results in listbox
lstboxOutput.Items.Clear()
lstboxOutput.Items.Add("Invoice number: " & custinvoicenum)
lstboxOutput.Items.Add("")
lstboxOutput.Items.Add("Name: " & custname)
lstboxOutput.Items.Add("Address: " & custaddress)
lstboxOutput.Items.Add("City: " & custcitystzip)
lstboxOutput.Items.Add("")
lstboxOutput.Items.Add("Number of Chiars: " & orderedchairs)
lstboxOutput.Items.Add("Number of Sofas: " & orderedsofas)
lstboxOutput.Items.Add("")
lstboxOutput.Items.Add(" Cost: " & FormatCurrency(costoutput))
lstboxOutput.Items.Add("Sales Tax: " & FormatCurrency(salestax))
lstboxOutput.Items.Add(" ----------------")
lstboxOutput.Items.Add("Total Cost: " & FormatCurrency(totalcost))
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
'Clears the textboxes and listboxes on the form when the clear button is clicked
txtboxAddress.Text = ""
txtboxChairs.Text = ""
txtboxCityStateZip.Text = ""
txtboxName.Text = ""
txtboxSofas.Text = ""
lstboxOutput.Items.Clear()
End Sub
Private Sub btnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuit.Click
'Closes the form when the quit button is clicked
Me.Close()
End Sub
Private Function Left(ByVal custname As String, ByVal p2 As Long) As String
Throw New NotImplementedException
End Function
End Class
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|