CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2013

    Cool Visual Basic - Calculations across multiple forms


    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.

    '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
    '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.

    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
            'Loop to fill in labels with "Ski" and "income"
            For countLabels As Integer = 0 To 1
                lstIncome.Items(countLabels * 8) = strIncomeHeader(countLabels).ToString
            'Loop to fill in the 5 brands of skis
            For SkiLabels As Integer = 0 To 4
                lstIncome.Items(SkiLabels + 1) = strSkiMake(SkiLabels)
            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:
       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
            Dim totalRevRegion As Double
            'Calculate total revenue for all products per region
            totalRevRegion = annualIncome.lblTotal.ToString
            lstTotalIncome.Items(0) = totalRevRegion
    Last edited by GremlinSA; November 22nd, 2013 at 01:29 PM. Reason: added code tags

  2. #2
    Join Date
    Jul 2005

    Re: Visual Basic - Calculations across multiple forms

    It would be better to move the thread to vb.net
    Last edited by jggtz; November 22nd, 2013 at 02:18 PM.

    ... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...

  3. #3
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008

    Re: Visual Basic - Calculations across multiple forms

    Moved to VB.Net section
    Always use [code][/code] tags when posting code.

Posting Permissions

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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.