Hi all

I've been editing some code I found on here from a while back and am up to trying to print out the data I store in an array. I've been trying for a bit and just don't understand it very well. Could someone give me a hand :)

Daily Summary Class

Public Class DailySummary
    Inherits Order

    Private orders As New ArrayList()
    Private totalOfPlainSausages As Double
    Private totalOfOnions As Double
    Private summaryDate As Date
    Private totalOrderAmount As Double
    Private totalAmountDue As Double
    Private totalAmountPaid As Double
    Private totalChangeDue As Double
    Private totalSalesTax As Double
    Private theOrder As Order

    Public Sub New(ByVal aNumberOfPlainSausages As Double, ByVal aNumberOfOnions As Double, ByVal anAmountPaid As Double)

        MyBase.New(aNumberOfPlainSausages, aNumberOfOnions, anAmountPaid)
        SettotalOfOnions(aNumberOfPlainSausages)
        SettotalOfPlainSausages(aNumberOfOnions)
        SetTotalAmountPaid(anAmountPaid)
        SetTotalAmountDue(GetAmountDue())
        SetTotalChangeDue(GetChangeDue())
        SetTotalSalesTax(SalesTax())
        SetTotalOrderAmount(OrderAmount())
        AssignOrderToOrder(aNumberOfPlainSausages, aNumberOfOnions, anAmountPaid)

    End Sub

    Public Overrides Function ToString() As String

        Return totalOfPlainSausages & " Plain Sausages @ " & FormatCurrency(PLAIN_SAUSAGE_PRICE) & ": " & (totalOfPlainSausages * PLAIN_SAUSAGE_PRICE) & vbNewLine & _
        totalOfOnions & " Onions @ " & FormatCurrency(Onions_PRICE) & ": " & (totalOfOnions * Onions_PRICE) & vbNewLine & _
        " Order Amount: " & FormatCurrency(totalOrderAmount) & vbNewLine & _
        " Sales Tax: " & FormatCurrency(totalSalesTax) & vbNewLine & _
        " Amount Due: " & FormatCurrency(totalAmountDue) & vbNewLine & _
        " Amount Paid: " & FormatCurrency(totalAmountPaid) & vbNewLine & _
        " Change Due: " & FormatCurrency(totalChangeDue)

    End Function

    Public Sub StoreOrder(ByVal aOrders As Order)
        orders.Add(aOrders)
    End Sub
    'get accessor methods

    Public Function GetOrder() As ArrayList
        Return orders
    End Function

    Public Function GetTotalOrderAmount() As Double
        Return totalOrderAmount
    End Function

    Public Function GetTotalAmountDue() As Double
        Return totalAmountDue
    End Function

    Public Function GetTotalAmountPaid() As Double
        Return totalAmountPaid
    End Function

    Public Function GetTotalChangeDue() As Double
        Return totalChangeDue
    End Function

    Public Function GetTotalSalesTax() As Double
        Return totalSalesTax
    End Function

    Public Sub AssignOrderToOrder(ByVal aNumberOfPlainSausages As Double, ByVal aNumberOfOnions As Double, ByVal anAmountPaid As Double)
        Dim order1 As New Order(aNumberOfPlainSausages, aNumberOfOnions, anAmountPaid)
        SetOrder(order1)
        order1.SetDailySummary(Me)
    End Sub

    Public Function GettotalOfPlainSausages() As Double
        Return totalOfPlainSausages
    End Function

    Public Function GettotalOfOnions() As Double
        Return totalOfOnions
    End Function

    Public Function GetSummaryDate() As Date
        Return summaryDate
    End Function
    'set accessor methods

    Public Sub SettotalOfPlainSausages(ByVal atotalOfPlainSausages As Double)
        totalOfPlainSausages += atotalOfPlainSausages
    End Sub

    Public Sub SettotalOfOnions(ByVal atotalOfOnions As Double)
        totalOfOnions += atotalOfOnions
    End Sub

    Public Sub SetSummarydate(ByVal aSummaryDate As Date)
        summaryDate = aSummaryDate
    End Sub

    Public Sub SetOrder(ByVal aOrder As Order)
        theOrder = aOrder
    End Sub

    Public Sub SetTotalAmountDue(ByVal aTotalAmountDue As Double)
        totalAmountDue += aTotalAmountDue
    End Sub

    Public Sub SetTotalOrderAmount(ByVal aTotalOrderAmount As Double)
        totalOrderAmount += aTotalOrderAmount
    End Sub

    Public Sub SetTotalAmountPaid(ByVal aTotalAmountPaid As Double)
        totalAmountPaid += aTotalAmountPaid
    End Sub

    Public Sub SetTotalChangeDue(ByVal aTotalChangeDue As Double)
        totalChangeDue += aTotalChangeDue
    End Sub

    Public Sub SetTotalSalesTax(ByVal aTotalSalesTax As Double)
        totalSalesTax += aTotalSalesTax
    End Sub

End Class

Order Class

Public Class Order
    'Constant variables
    Public Const PLAIN_SAUSAGE_PRICE As Double = 3.0
    Public Const Onions_PRICE As Double = 0.5
    Public Const SAUCE_PRICE As Double = 0.2
    Public Const SALES_TAX_RATE As Double = 0.1
    Private numberOfPlainSausages As Double
    Private numberOfOnions As Double
    Private amountPaid As Double
    Private amountDue As Double
    Private changeDue As Double
    Private theDailySummary As DailySummary

    Public Sub New(ByVal aNumberOfPlainSausages As Double, ByVal aNumberOfOnions As Double, ByVal anAmountPaid As Double)
        SetNumberOfPlainSausages(aNumberOfPlainSausages)
        SetNumberOfOnions(aNumberOfOnions)
        SetAmountPaid(anAmountPaid)
        OrderAmount()
        SalesTax()
        SetAmountDue()
        SetChangeDue()
    End Sub

    Public Overrides Function ToString() As String
        Return numberOfPlainSausages & " Plain Sausages @ " & FormatCurrency(PLAIN_SAUSAGE_PRICE) & ": " & (numberOfPlainSausages * PLAIN_SAUSAGE_PRICE) & vbNewLine & _
        numberOfOnions & " Onions @ " & FormatCurrency(Onions_PRICE) & ": " & (numberOfOnions * Onions_PRICE) & vbNewLine & _
        " Order Amount: " & FormatCurrency(OrderAmount()) & vbNewLine & _
        " Sales Tax: " & FormatCurrency(SalesTax()) & vbNewLine & _
        " Amount Due: " & FormatCurrency(amountDue) & vbNewLine & _
        " Amount Paid: " & FormatCurrency(amountPaid) & vbNewLine & _
        " Change Due: " & FormatCurrency(changeDue)
    End Function

    Public Function OrderAmount() As Double
        Dim aOrderAmount As Double
        aOrderAmount = (numberOfPlainSausages * PLAIN_SAUSAGE_PRICE + numberOfOnions * Onions_PRICE)
        Return aOrderAmount
    End Function

    Public Function SalesTax() As Double
        Dim aSalesTax As Double
        aSalesTax = (OrderAmount() * SALES_TAX_RATE)
        Return aSalesTax
    End Function

    Public Function GetAmountDue() As Double
        Return amountDue
    End Function

    Public Sub SetAmountDue()
        amountDue = OrderAmount() + SalesTax()
    End Sub

    Public Function GetChangeDue() As Double
        Return changeDue
    End Function

    Public Sub SetChangeDue()
        changeDue = amountPaid - amountDue
    End Sub

    Public Function GetNumberOfPlainSausages() As Double
        Return numberOfPlainSausages
    End Function

    Public Sub SetNumberOfPlainSausages(ByVal aNumberOfPlainSausages As Double)
        numberOfPlainSausages = aNumberOfPlainSausages
    End Sub

    Public Function GetNumberOfOnions() As Double
        Return numberOfOnions
    End Function

    Public Sub SetNumberOfOnions(ByVal aNumberOfOnions As Double)
        numberOfOnions = aNumberOfOnions
    End Sub

    Public Function GetAmountPaid() As Double
        Return amountPaid
    End Function

    Public Sub SetAmountPaid(ByVal anAmountPaid As Double)
        amountPaid = anAmountPaid
    End Sub

    Public Sub SetDailySummary(ByVal aDailySummary As DailySummary)
        theDailySummary = aDailySummary
    End Sub

End Class

Form 1

Public Class Form1
    Inherits System.Windows.Forms.Form

    'Declare order reference variable
    Private aDailySummary As DailySummary
    Private aOrder As Order

    'Declare string variables for numberOfPlainSausagess and numberOfOnions
    Private custNumOfPlainSausages, custNumOfOnions, custNumOfSauce, custNumOfCurriedSausages As Double
    Private custNumOfPlainSausages2, custNumOfOnions2, custNumOfSauce2, custNumOfCurriedSausages2 As Double
    Private custAmtPaid As Double
    Private custAmtPaid2 As Double

    Dim filename As String

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        custNumOfPlainSausages = txtPlainSausage.Text
        custNumOfOnions = txtOnion.Text
        custAmtPaid = txtAmtPaid.Text
        Dim order1 As New Order(custNumOfPlainSausages, custNumOfOnions, custAmtPaid)
        Dim dailySummary As New DailySummary(custNumOfPlainSausages, custNumOfOnions, custAmtPaid)
        dailySummary.StoreOrder(order1)
        txtOutput.Text = dailySummary.ToString
        txtReceipt.Text = order1.ToString
        'ClearForm()

    End Sub

    Private Sub Button5_Click(sender As System.Object, e As System.EventArgs) Handles Button5.Click
        txtOutput.Clear()
        txtReceipt.Clear()
        txtAmtPaid.Clear()
        txtCurriedSausage.Clear()
        txtOnion.Clear()
        txtPlainSausage.Clear()
        txtSauce.Clear()
    End Sub

    Private Sub Button6_Click(sender As System.Object, e As System.EventArgs) Handles btnCloseSession.Click
        End
    End Sub


    Private Sub btnPrintOrder_Click(sender As System.Object, e As System.EventArgs) Handles btnPrintOrder.Click
        filename = "Sales.txt"
        PrintPreviewDialog1.Document = PrintDocument1
        PrintPreviewDialog1.ShowDialog()
    End Sub

    Private Sub PrintDocument1_PrintPage(sender As System.Object, e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage

        Dim MyFont As New Font("Courier New", 12, FontStyle.Regular)
        Dim MyFormat As String = "{0,-29}{1,-10}{2,-12}" '3 column format
        Dim Name, Region, LineToPrint As String
        Dim X, Y, Amount, FontHeight As Integer
        X = 50
        Y = 50
        FontHeight = MyFont.GetHeight(e.Graphics) 'height of 1 line of font used
        Name = "No file found"
        Region = "No data"
        'print report title
        e.Graphics.DrawString("Report on daily sales made by sales staff", MyFont, Brushes.Black, X, Y)
        Y = Y + FontHeight      'reset y for next line of printing
        e.Graphics.DrawString("", MyFont, Brushes.Black, X, Y) 'blank line
        Y = Y + FontHeight
        LineToPrint = String.Format(MyFormat, "Salesperson", "Products", "Amount Sold")
        e.Graphics.DrawString(LineToPrint, MyFont, Brushes.Black, X, Y)
        Y = Y + FontHeight
        e.Graphics.DrawString("", MyFont, Brushes.Black, X, Y) 'blank line
        FileOpen(1, filename, OpenMode.Input)
        Do While Not EOF(1)
            Input(1, Name)
            Input(1, Region)
            Input(1, Amount)
            Y = Y + FontHeight ' reset Y for printing next salesperson
            LineToPrint = String.Format(MyFormat, Name, Region, Format(Amount * 1000, "$#,##0"))
            'print details of one salesperson
            e.Graphics.DrawString(LineToPrint, MyFont, Brushes.Black, X, Y)
        Loop
        FileClose(1)
    End Sub

End Class

Is there something wrong with the code or are you just trying to make sense of it?

Code works fine. I'm just trying to get the print to work. I'm not entirely sure how to store my programs data in a file or an array and then have it printed.

For that ypu might be better off creating a form with all your data presented how you want it to look and use the printform control.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.