0

I need help creating a batch of Grand Totals each time enter my value and click Calculate.
The code below gives me my Grand Total, now I would like to enter a new set of values and store the previous amount(s) until I'm ready to populate them in a Message Box. Any Suggestions! Thanks!

Public Class frmTotalDailySales
    Dim ItemCost() As Decimal = {12D, 17.95D, 95D, 86.5D, 78D}
 

    Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click


        Dim SoldItems(,) As Integer = New Integer(,) {{txtS1I1.Text, txtS1I2.Text, txtS1I3.Text, txtS1I4.Text, txtS1I5.Text}, _
                                {txtS2I1.Text, txtS2I2.Text, txtS2I3.Text, txtS2I4.Text, txtS2I5.Text}, _
                                {txtS3I1.Text, txtS3I2.Text, txtS3I3.Text, txtS3I4.Text, txtS3I5.Text}}

        Dim totals(,) As Decimal = Calculate(SoldItems, ItemCost)
    End Sub


    Private Function Calculate(ByVal SoldItems(,) As Integer, ByVal itemCost() As Decimal) As Decimal(,)


        Dim SalesRevenue(SoldItems.GetUpperBound(0), SoldItems.GetUpperBound(1)) As Decimal
        Dim strItemsSold As String = ""
        Dim totals(SoldItems.GetUpperBound(0)) As Decimal


        For r As Integer = 0 To SoldItems.GetUpperBound(0)
            For c As Integer = 0 To SoldItems.GetUpperBound(1)
                SalesRevenue(r, c) = CDec(SoldItems(r, c) * itemCost(c))
                strItemsSold &= FormatCurrency(SalesRevenue(r, c), 2) & vbTab
                totals(r) += SalesRevenue(r, c)
            Next
            strItemsSold &= vbCrLf & vbCrLf
            txtTotalStoreSales1.Text = FormatCurrency(totals(0).ToString, 2)
            txtTotalStoreSales2.Text = FormatCurrency(totals(1).ToString, 2)
            txtTotalStoreSales3.Text = FormatCurrency(totals(2).ToString, 2)
        Next

        Dim sum As Decimal = 0
        For Each total As Decimal In totals
            sum += total
        Next
        txtDailyTotal.Text = FormatCurrency(sum, 2)

        MessageBox.Show(strItemsSold, "Daily Sales Revenue")

        Return SalesRevenue
    End Function
2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by Oxiegen
0

A suggestion:
Add a class variable of type List(Of Object).
For each time you press the btnCalculate button you add totals(,) to that variable.
Then iterate through the list and add it's content to a string variable that you display in a MessageBox.

Example:

Private Sub example()
            Dim values As New List(Of Object)
            Dim text As String = ""

            For Each item As Decimal In values
                text &= item.ToString & vbCrLf
            Next
            MessageBox.Show(text)
        End Sub
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.