Hello,
I have been trying for days to figure out how to calculate "total revenue" on a new form using a listbox control. Any help would be much appreciated.
Code:
'MainForm' displays the form 'AnnualIncome'
Private Sub mnuCalculateAnnualIncome_Click(sender As System.Object, e As System.EventArgs) Handles mnuCalculateAnnualIncome.Click
'Create an instance of "Annual Income" form
Dim frmAnnualIncome As New annualIncome
'Dispaly the annual income Form in modeless style
frmAnnualIncome.Show()
'AnnualIncome' form then calculates annual income (per region). I have 3 regions. When you select a different region sales are calculated for all products across the entire region and displays results in a listbox. This part works fine.
Code:
Private Sub annualIncome_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'Loop to fill in 14 cells
For lstSalesData As Integer = 0 To 14
lstIncome.Items.Add("")
Next
'Loop to fill in labels with "Ski" and "income"
For countLabels As Integer = 0 To 1
lstIncome.Items(countLabels * 8) = strIncomeHeader(countLabels).ToString
Next
'Loop to fill in the 5 brands of skis
For SkiLabels As Integer = 0 To 4
lstIncome.Items(SkiLabels + 1) = strSkiMake(SkiLabels)
Next
Dim skiRevenue As Double
'Calculates and displays total revenue for each Ski Brand
skiRevenue = MainForm.lstSales.Items(15) * MainForm.lstSales.Items(1)
lstIncome.Items(9) = skiRevenue
skiRevenue = MainForm.lstSales.Items(31) * MainForm.lstSales.Items(17)
lstIncome.Items(10) = skiRevenue
skiRevenue = MainForm.lstSales.Items(47) * MainForm.lstSales.Items(33)
lstIncome.Items(11) = skiRevenue
skiRevenue = MainForm.lstSales.Items(63) * MainForm.lstSales.Items(49)
lstIncome.Items(12) = skiRevenue
skiRevenue = MainForm.lstSales.Items(79) * MainForm.lstSales.Items(65)
lstIncome.Items(13) = skiRevenue
Dim totalRevenue As Double
'Calculate total revenue for all products
totalRevenue = lstIncome.Items(9) + lstIncome.Items(10) + lstIncome.Items(11) + lstIncome.Items(12) + lstIncome.Items(13)
lblTotal.Text = totalRevenue.ToString("C")
End Sub
THE THIRD FORM 'totalIncome' should display the total income of each of the 3 regions and then calculate the total of all three regions.
I have tried something similar to the following but am not having any luck:
Code:
Private Sub totalIncome_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'Loop to fill in 8 Cells
For lstSalesData As Integer = 0 To 7
lstTotalIncome.Items.Add("")
Next
Dim totalRevRegion As Double
'Calculate total revenue for all products per region
totalRevRegion = annualIncome.lblTotal.ToString
lstTotalIncome.Items(0) = totalRevRegion