I am so lost on how to get this code to work, and I am pretty sure what I have is all wrong.

The problem is as follows:
Each salesperson is assigned a 4 character ID, with the first character either an F (full-time) or a P (part-time). And the last character is either a 1 (sells new cars) or a 2 (sells used cars).

I need to create an application that allows the sales manager to enter a ID and the number of cars the salesperson sold during the month. The app should all the sales manager to enter this info for as many salespeople as he likes. The app needs to calculate and display the total number of cars sold by each of the following: full-time employees, part-time employees, employees that sell new cars and employees that sell used cars.

I have the following code which works so to speak, but it doesn't total the amounts of cars sold if more than one salesperson ID is entered. And in general I think what works in this code, just works, but isn't actually correct.

Private Sub calcButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calcButton.Click
        ' Define Variables
        Dim id As String = String.Empty

        id = salesIDTextBox.Text.ToUpper

        If id.StartsWith("F") And id.EndsWith("1") Then
            noFulltimeLabel.Text = carsSoldTextBox.Text
            noNewCarLabel.Text = carsSoldTextBox.Text
        ElseIf id.StartsWith("F") And id.EndsWith("2") Then
            noFulltimeLabel.Text = carsSoldTextBox.Text
            noUsedCarLabel.Text = carsSoldTextBox.Text
        ElseIf id.StartsWith("P") And id.EndsWith("1") Then
            noParttimeLabel.Text = carsSoldTextBox.Text
            noNewCarLabel.Text = carsSoldTextBox.Text
        ElseIf id.StartsWith("P") And id.EndsWith("2") Then
            noParttimeLabel.Text = carsSoldTextBox.Text
            noUsedCarLabel.Text = carsSoldTextBox.Text
        Else
            MessageBox.Show("Incorrect employee ID number. ID must begin with F or P and end with 1 or 2.", _
                            "BobCat Motors", MessageBoxButtons.OK, _
                            MessageBoxIcon.Information)

        End If

        salesIDTextBox.Focus()

Honestly, I don't know where to begin. Any help would be appreciated.

Seriously, could use some help here.

Now my code is as follows (which still isn't correct).

Dim id As String = String.Empty
        Dim cars As Integer
        Static fulltime As Integer
        Static fullNew As Integer
        Static fullUsed As Integer

        id = salesIDTextBox.Text.ToUpper

            If id.StartsWith("F") And id.EndsWith("1") Then
                cars = CInt(carsSoldTextBox.Text)
            ElseIf id.StartsWith("P") And id.EndsWith("1") Then
                cars = CInt(carsSoldTextBox.Text)
            End If

        fulltime = fulltime + cars
        fullNew = fullNew + cars
        fullUsed = fullUsed + cars

        noFulltimeLabel.Text = CStr(fulltime)
        noNewCarLabel.Text = CStr(fullNew)
        noUsedCarLabel.Text = CStr(fullUsed)

        salesIDTextBox.Focus()

Sorry, I'm just trying to understand exactly what is happening you say:

The problem is as follows:
Each salesperson is assigned a 4 character ID, with the first character either an F (full-time) or a P (part-time). And the last character is either a 1 (sells new cars) or a 2 (sells used cars).

I need to create an application that allows the sales manager to enter a ID and the number of cars the salesperson sold during the month. The app should all the sales manager to enter this info for as many salespeople as he likes. The app needs to calculate and display the total number of cars sold by each of the following: full-time employees, part-time employees, employees that sell new cars and employees that sell used cars.

Do you mean that the manager enters the data for a single salesperson in then the next and gets a running total? Or do you mean that they enter multiple user ID at once and want to display the totals?

I'll assume the first scenario - the running total. the issue is that with each click you are "resetting" the totals:

If id.StartsWith("F") And id.EndsWith("1") Then            
noFulltimeLabel.Text = carsSoldTextBox.Text           'i.e. the noFulltimeLabel text is now the same as the carsSoldTextBox text

What you want to do is something like this:

If id.StartsWith("F") And id.EndsWith("1") Then            
noFulltimeLabel.Text = Cint(noFulltimeLabel.Text)  + Cint(carsSoldTextBox.Text )

Right now I’m a bit Busy, I will give you a small help to start.

You need to make a Private Dictionary to store all the Sales

Private _SPCars As New Dictionary(Of String, Integer)

Make a 2 Textbox where the User can enter the SalePerson and the Amount of Car Solded. And in a Button you must add the code to add to the Dictionary
Add to the Dictionary eg
Please Replace the "<SalesPersonID>" and "<NumberOfCars>" with the Text from the textbox

If _SPCars.ContainsKey("<SalesPersonID>") Then
' Found just add to the Cars he already Sold
_SPCars("<SalesPersonID>") = _SPCars("<SalesPersonID>") + "<NumberOfCars>"
Else
' New Sale Person
_SPCars.Add("<SalesPersonID>", "<NumberOfCars>")
End If

Now with LINQ you can easy get the Totals

Dim TotalFullTime = (From SPCar In _SPCars _
                             Where SPCar.Key.StartsWith("F") _
                             Select SPCar.Value).Sum

        Dim TotalPartTime = (From SPCar In _SPCars _
                             Where SPCar.Key.StartsWith("P") _
                             Select SPCar.Value).Sum

        Dim ListOfSalePersonThatSoldNewCar = From SPCar In _SPCars _
                                             Where SPCar.Key.EndsWith("1") _
                                             Select SPCar.Key


        Dim ListOfSalePersonThatSoldUSedCar = From SPCar In _SPCars _
                                              Where SPCar.Key.EndsWith("2") _
                                              Select SPCar.Key

Hope this will help you...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.