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

New Topic/Question
Reply



MultiQuote





|