Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27083

Having problems with my Array :(

$
0
0
Check the results of “Number of Agencies Needed” after clicking “Select Media and Estimated Fund.” Then select the names of the agencies from the agency listbox on the left and click “Add Agencies.” When the “Add Agencies:” button is clicked, the name of the selected agencies should appear in
the listbox next to the agency list. Here is the list of agencies, which should be input in the agency listbox on the left.

U-Ad ($350), Striker ($190), NewAd ($250), Samson ($530), J & R ($420), Victory ($120).

When the “Add Agencies:” button is clicked, the results of the calculated estimated cost should appear in the textbox next to “Total Estimated Cost.”
For example, if you selected “U-Ad” and “Samson,” then the total estimated cost would be $880.00; the results should appear when you click “Add Agencies:” When you add more agencies, such calculated estimated costs should be updated.

Code:

Private Sub btnAddAgencies_Click(sender As Object, e As EventArgs) Handles btnAddAgencies.Click

        Dim selectedItems = (From i In lstBoxAgenciesList.SelectedItems).ToArray()

        For Each selectedItem In selectedItems

            lstBoxSelectedList.Items.Add(selectedItem)
            lstBoxAgenciesList.Items.Remove(selectedItem)

        Next

        Dim list(0 To 6) As Double
        Dim total As Double = 0
        Dim p As Integer = 0

        list(0) = 350
        list(1) = 190
        list(2) = 250
        list(3) = 530
        list(4) = 420
        list(5) = 120

        While (p < list.Length())

            total += list(p)
            p += 1

            txtBoxEstimatedCost.Text = total

        End While

    End Sub

I have the first part working perfectly, but the second part isn't working very well. It is adding up all of the numbers instead of the ones the user selected.....

Thanks for your help!

Viewing all articles
Browse latest Browse all 27083

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>