6 Replies - 688 Views - Last Post: 17 February 2013 - 06:44 PM Rate Topic: -----

#1 cowandering  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 17-February 13

Non- book standard JM Sales assignment

Posted 17 February 2013 - 01:54 PM

Hi all,
I just don't quite understand and am hoping that someone here might help me understand what needs to happen. I have watched YouTube videos on this as well as all the videos from the book and just can't seem to figure this out.

"JM Sales employs five salespeople. The sales manager wants an application that allows him to enter any number of sales amounts for each of the five salespeople. The application should accumulate the sales amounts in a one-dimensional array. The application also should display an on-form “report” with the resulting data as indicated in the sample form below. That display should contain each salesperson’s ID and total sales. It also should display the total company sales. We suggest that the textbox that displays the resulting data has its BorderStyle property set to Fixed3D, its Font property set to Courier New 10 point, its MultiLine and ReadOnly properties set to True, and its ScrollBars property set to Vertical. Test it thoroughly with many possible additional combinations of data."

What I am getting with the code below and several previous variants that I have written over the past week and a half is that the final sales id of "302" shows up with whatever value is typed into the salesTextBox. It does not matter which other salesid is selected, it always returns "302". And it does not accumulate as it should.

I have attempted to enter the code so that only numbers and the backspace are accepted into the salesTextBox but that code does not seem to work either. I haven't really tried to get the report to run yet as I cannot seem to the values to accumulate accurately, so why even attempt to run the report.

Any guidance on what I am doing wrong would be greatly appreciated! I will have to admit, the code might be way off base at this point as it is an accumulation of several days of watching videos and trying different things and nothing seems to work.

Option Explicit On
Option Strict On
Option Infer Off

Public Class JMSales

    Private salesid() As Integer = {"101", "112", "203", "301", "302"}

    Private Sub salesTextBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles salesTextBox.KeyPress
        'accepts only numbers and the Backspace key

        If (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso
            e.KeyChar <> ControlChars.Back Then
            e.Handled = True
        End If
    End Sub

    Private Sub 
        ClearList()
        totalsTextBox.Text = String.Empty
    End Sub

    Private Sub totalsButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles totalsButton.Click
        'declare variables
        Dim sales As Double
        Dim subscript As Integer
        Dim inputsales As Integer
        Dim salesAccumulator As Double

        Integer.TryParse(salesidListBox.SelectedItem, salesid(4))
        Double.TryParse(salesTextBox.Text, sales)
        subscript = salesidListBox.SelectedItem
        inputsales = salesTextBox

        'update array value
        For Each subscript As Integer In salesid
            salesAccumulator += sales
        Next subscript

        ' Update accumulator 
        salesAccumulator = salesAccumulator + sales

        ' perform calculations for each salesid

    End Sub
    'will generate a report showing all individual sales id's sales as well as total sale
    Private Sub createButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles createButton.Click

        'declare variables
        Dim sales As Double
        Dim subscript As Integer

        Double.TryParse(salesTextBox.Text, sales)
        subscript = salesidListBox.SelectedItem
        Array.Sort(salesid)

        'perform calculation for total sales
        X = salesid(0) + salesid(1) + salesid(2) + salesid(3) + salesid(4)


        'display array values in Sales Totals

        For subscript As Integer = (salesid() & "     " & sales & ControlChars.NewLine)
        Next subscript

    End Sub

    Private Sub exitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles exitButton.Click
        Me.Close()
    End Sub

End Class



Is This A Good Question/Topic? 0
  • +

Replies To: Non- book standard JM Sales assignment

#2 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: Non- book standard JM Sales assignment

Posted 17 February 2013 - 02:19 PM

For starters, have a look at your code in the editor. You have Option Strict On, so you should be seeing some things that are underlined with little blue wiggly lines. Each one indicates an error.

The first order of business is to eliminate these errors.

If you drive your mouse cursor over the wiggly line, you'll see what the error is, and in some cases, near the end of the line, you can seean eclamation mark. Clicking on it will often suggest a fix.

Give that a try, and see if things change.
Was This Post Helpful? 0
  • +
  • -

#3 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3190
  • View blog
  • Posts: 10,681
  • Joined: 12-December 12

Re: Non- book standard JM Sales assignment

Posted 17 February 2013 - 02:56 PM

In addition to lar3rys comments, the most obvious error is more or less on the first line:

Private salesid() As Integer = {"101", "112", "203", "301", "302"}

You have declared these as integers but are quoting them as "strings".

When you attempt to Build your project it also produces a lot of error messages which you can double-click on and it will take you to the error, and often offer corrections for them: I'm surprised you haven't noticed, or used, this feature :whistling: - it makes it very hard to make mistakes..

This post has been edited by andrewsw: 17 February 2013 - 02:57 PM

Was This Post Helpful? 0
  • +
  • -

#4 cowandering  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 17-February 13

Re: Non- book standard JM Sales assignment

Posted 17 February 2013 - 03:40 PM

Thanks for the feedback.

So I have updated the salesid() As String = {"101", etc}. I have also hovered over the exclamation points and moved forward with the recommendations that were made.

However, the code still populates "302####" where #### = whatever number I put in the salesTextBox. It still disregards whichever value I have selected in the list box. And it does not accumulate values either.

Here is the updated code

Option Explicit On
Option Strict On
Option Infer Off

Public Class JMSales

    Private salesid() As String = {"101", "112", "203", "301", "302"}


    Private Sub salesTextBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles salesTextBox.KeyPress
        'accepts only numbers and the Backspace key

        If (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso
            e.KeyChar <> ControlChars.Back Then
            e.Handled = True
        End If
    End Sub

    Private Sub ClearList()
        totalsTextBox.Text = String.Empty
    End Sub

    Private Sub totalsButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles totalsButton.Click
        'declare variables
        Dim sales As Double
        Dim subscript As Integer
        Dim inputsales As Integer
        Dim salesAccumulator As Double

        Integer.TryParse(CStr(salesidListBox.SelectedItem), CIntsalesid(4))
        Double.TryParse(salesTextBox.Text, sales)
        subscript = CInt(salesidListBox.SelectedItem)

        'update array value
        For Each subscript As Integer In salesid
            salesAccumulator += sales
        Next subscript

        ' Update accumulator 
        salesAccumulator = salesAccumulator + sales

        ' perform calculations for each salesid

    End Sub
    'will generate a report showing all individual sales id's sales as well as total sale
    Private Sub createButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles createButton.Click

        'declare variables
        Dim sales As Double
        Dim subscript As Integer
        Dim total As Double

        Double.TryParse(salesTextBox.Text, sales)
        subscript = CInt(salesidListBox.SelectedItem)
        Array.Sort(salesid)

        'perform calculation for total sales
        For total As Double = salesid(0) + salesid(1) + salesid(2) + salesid(3) + salesid(4)


            'display array values in Sales Totals

        For subscript As Integer = CInt((salesid(4) & "     " & sales & ControlChars.NewLine))
            Next subscript

    End Sub

    Private Sub exitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles exitButton.Click
        Me.Close()
    End Sub

    Private Function CIntsalesid(ByVal p1 As Integer) As Integer
        Throw New NotImplementedException
    End Function

End Class


Was This Post Helpful? 0
  • +
  • -

#5 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3190
  • View blog
  • Posts: 10,681
  • Joined: 12-December 12

Re: Non- book standard JM Sales assignment

Posted 17 February 2013 - 03:54 PM

There are still errors and warnings in your code. This line

For total As Double = salesid(0) + salesid(1) + salesid(2) + salesid(3) + salesid(4)

in particular is wrong.

Why did you convert the salesid's to strings if you intend to add them? But, if they are ids, why are you adding them?
Was This Post Helpful? 0
  • +
  • -

#6 cowandering  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 17-February 13

Re: Non- book standard JM Sales assignment

Posted 17 February 2013 - 04:27 PM

Andrewsw,

What I thought would happen here is that the final total value would be populated below the string of salesids. So the bottom text box is supposed to read something like:
101 17,500
112 12,500
203 10,000
301 15,000
302 20,000

Total = 75,000

The values for each salesid is accumulated for that sales id through the process of the "totalsButton" click event.

I thought to total all of the sales ids, one would have to add them together. Apparently that is not the case.

I am really not sure what I am doing wrong, other than there is a bunch of what I am doing wrong.....
Was This Post Helpful? 0
  • +
  • -

#7 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: Non- book standard JM Sales assignment

Posted 17 February 2013 - 06:44 PM

View Postcowandering, on 17 February 2013 - 05:27 PM, said:

What I thought would happen here is that the final total value would be populated below the string of salesids. So the bottom text box is supposed to read something like:
101 17,500
112 12,500
203 10,000
301 15,000
302 20,000

Total = 75,000

The values for each salesid is accumulated for that sales id through the process of the "totalsButton" click event.

I thought to total all of the sales ids, one would have to add them together. Apparently that is not the case.


Eh? A sales ID is like an employee number. If you are a salesman with an employee number of 102, and your friend Bill is a salesman with an employee number of 302, how could adding the employee numbers together show anything at all about the amount of sales they each made?

You really need to think about what your program should do, rather than just writing random code that sums things that are unrelated to the problem at hand.

Are you really sure you are still compiling with Option Strict On? When I paste your code into my Visual Studio, I get errors on line 35 (variable "subscript" hides a variable in an enclosing block), line 58 ("For" must end with a matching "Next", as well as something that tells you you can'r implicitly convert a string to a double, and in line 63, again hiding a variable in a block.

How are you compiling with these errors? With Option Strict On, you should not be able to.

Oh, and the reason you are getting "302xxx" is because you are telling it to do that in line 63.

I'm not sure why you don't get an error on line 30, but it's definitely wrong. You have forgotten a "(" after Cint.

Integer.TryParse(CStr(salesidListBox.SelectedItem), CIntsalesid(4))


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1