I am very new to vb.net. I just starting taking it at school and I am having a hard time with it. Here is an order project we need to do for class. I can't get rid of the comma between the names in the list box and my decimals don't seem to line up either. I am very frustrated with this any help would be appreciated. Thanks.

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Customer, Last, First, Address, City, Chairs, Sofas, Invoicenumber As String
        Dim CommaName As Integer
        Dim Datum As IO.StreamReader = IO.File.OpenText("C:\Temp\assign2.txt")
        Dim Chair, Sofa, Tax, Cost, SalesTax, Total As Double
        Chair = CDbl(Datum.ReadLine) * txtchairs.Text
        Sofa = CDbl(Datum.ReadLine) * txtsofas.Text
        Tax = CDbl(Datum.ReadLine)
        Cost = Chair + Sofa
        SalesTax = (Chair + Sofa) * Tax
        Total = Chair + Sofa + SalesTax

        Customer = txtcustomer.Text
        CommaName = Customer.IndexOf(",")
        Last = Customer.Substring(0, CommaName)
        First = Customer.Substring(Customer.Length - CommaName + 1)
        Address = txtaddress.Text
        City = txtcity.Text
        Chairs = txtchairs.Text
        Sofas = txtsofas.Text
        Invoicenumber = (Customer.Substring(0, 2).ToUpper & City.Substring(City.Length - 4).ToUpper)
        With ListBox.Items
            .Add("Invoice Number: " & vbTab & Invoicenumber)
            .Add("Name: " & vbTab & First & " " & Last)
            .Add("Address: " & vbTab & txtaddress.Text)
            .Add("City: " & vbTab & txtcity.Text)
            .Add("Number of Chairs: " & vbTab & txtchairs.Text)
            .Add("Number of Sofas:   " & vbTab & txtsofas.Text)
            .Add("        Cost: " & FormatCurrency(Cost))
            .Add(" Sales Tax: " & FormatCurrency(SalesTax))
            .Add("" & vbTab & "" & "----------------")
            .Add("Total Cost: " & FormatCurrency(Total))
        End With

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        ' Clear all display in text list box
        txtcustomer.Text = ""
        txtaddress.Text = ""
        txtcity.Text = ""
        txtchairs.Text = ""
        txtsofas.Text = ""
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    End Sub

    Private Sub ListBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox.SelectedIndexChanged

    End Sub
End Class

A couple of changes to your code.
1. A better name for CommaName is CommaPosition - more discriptive
2. When you get the first name use instead:

First = Trim(Customer.Substring(CommaPosition + 1))

If you don't give it a length it will take everything to the end of the text and the trim will get rid of any spaces.
Hope this helps.

This article has been dead for over six months. Start a new discussion instead.