Results 1 to 11 of 11

Thread: Need Help with a VB Error Number of indices....

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2011
    Posts
    12

    Need Help with a VB Error Number of indices....

    I am doing a midterm project and I am having some problems. Here is the assignment:

    JM Sales employs 8 salespeople. The sales manager wants an application that allows him to enter a bonus rate. The application should use the rate, along with the 8 salespeople, in an array, to calculate each salesperson's bonus amount. The application should display each salesperson's number (1 through 8) and bonus amount. as well as the total bonus paid, in the interface.

    I have the interface correct, my problem is with the section of code below where I am trying calculate the total bonus paid:

    Code:
    Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreate.Click
            Dim Sales() As Integer = {2400, 1500, 1600, 2790, 1000, 6300, 1300, 2700}
            
            Dim BonusRate As Double
            Dim K As Integer = 0
            Dim Report As String = "Bonus".PadLeft(7) & ControlChars.NewLine
            Dim TotalSales(9) As Integer
            Dim bonus() As Double
            Dim TotalBonus As Double
    
            Double.TryParse(txtRate.Text, BonusRate)
            Dim ValidBonus As Boolean = BonusRate > 0
    
            ReDim Preserve bonus(8)
    
            If ValidBonus Then
                If BonusRate > 0 Then
                    Do While K < 8
                        TotalSales(K) = Sales(K, 0) + Sales(K, 1)
                        bonus(K) = (TotalSales(K) * (BonusRate))
                        Report = Report & (K + 1).ToString().PadRight(2) & bonus(K).ToString("n2").PadLeft(5) & ControlChars.NewLine
                        TotalBonus = TotalBonus + bonus(K)
                        K = K + 1
                    Loop
                End If
                Report = Report & (K + 1).ToString().PadLeft(1) & ". " & bonus(K).ToString("n2").PadLeft(5) & ControlChars.NewLine
                txtReport.Text = Report
            Else
                MessageBox.Show("Please enter a numerical amount")
            End If
    
        End Sub

    The section below is generating the following 2 Errors:
    Number of indices exceeds the number of dimensions of the indexed array
    And is pointing out the 2 Red highlighted areas.

    Code:
    If ValidBonus Then
                If BonusRate > 0 Then
                    Do While K < 8
                        TotalSales(K) = Sales(K, 0) + Sales(K, 1)                    
    bonus(K) = (TotalSales(K) * (BonusRate))
                        Report = Report & (K + 1).ToString().PadRight(2) & bonus(K).ToString("n2").PadLeft(5) & ControlChars.NewLine
                        TotalBonus = TotalBonus + bonus(K)
                        K = K + 1
                    Loop
                End If
                Report = Report & (K + 1).ToString().PadLeft(1) & ". " & bonus(K).ToString("n2").PadLeft(5) & ControlChars.NewLine
                txtReport.Text = Report
            Else
                MessageBox.Show("Please enter a numerical amount")
            End If
    Any help on this would be greatly appreciated! Thanks
    Last edited by gep13; Mar 22nd, 2011 at 02:25 AM. Reason: Added Code Tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width