0 Replies - 1238 Views - Last Post: 04 December 2012 - 06:14 PM Rate Topic: -----

#1 jesuspaid  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 04-December 12

I am trying to print from an array.

Posted 04 December 2012 - 06:14 PM

I am trying to print out each food type with the subtotal for a transaction report. It will only print out my first indexinteger information which is "Beans". It will not print information about any other food type or total. I tried using different combo boxes and it does the same thing. I tried creating an new variable to substitute for the array but it did the same thing. I have looked in my book for the correct way to reference the parts of the structure but I couldn't find it. I really thought that the way I have it currently would have worked. But I am out of luck.

Thank you for your help.

This is my Input Form that I am working on I have also included my Home Form because it has my array and structure on it.

Public Class InputForm
    


    Private Sub AddButton_Click(sender As System.Object, e As System.EventArgs) Handles AddButton.Click
        Dim IndexInteger As Integer = 0
        Dim FoundBoolean As Boolean = False

        Do Until FoundBoolean Or IndexInteger > 9

            If InputComboBox1.Text = HomeForm.InventoryArray(IndexInteger).Name Then
                FoundBoolean = True
                HomeForm.InventoryArray(IndexInteger).ItemCount += Integer.Parse(InputTextBox1.Text)

                HomeForm.InventoryArray(IndexInteger).ItemSubTotal += HomeForm.InventoryArray(IndexInteger).ItemCount
                HomeForm.InventoryArray(IndexInteger).ItemGrandTotal += HomeForm.InventoryArray(IndexInteger).ItemSubTotal
            ElseIf InputComboBox2.Text = HomeForm.InventoryArray(IndexInteger).Name Then

                FoundBoolean = True
                HomeForm.InventoryArray(IndexInteger).ItemCount += Integer.Parse(InputTextBox2.Text)

                HomeForm.InventoryArray(IndexInteger).ItemSubTotal += HomeForm.InventoryArray(IndexInteger).ItemCount
                HomeForm.InventoryArray(IndexInteger).ItemGrandTotal += HomeForm.InventoryArray(IndexInteger).ItemSubTotal
            ElseIf InputComboBox3.Text = HomeForm.InventoryArray(IndexInteger).Name Then

                FoundBoolean = True
                HomeForm.InventoryArray(IndexInteger).ItemCount += Integer.Parse(InputTextBox3.Text)

                HomeForm.InventoryArray(IndexInteger).ItemSubTotal += HomeForm.InventoryArray(IndexInteger).ItemCount
                HomeForm.InventoryArray(IndexInteger).ItemGrandTotal += HomeForm.InventoryArray(IndexInteger).ItemSubTotal
            ElseIf InputComboBox4.Text = HomeForm.InventoryArray(IndexInteger).Name Then

                FoundBoolean = True
                HomeForm.InventoryArray(IndexInteger).ItemCount += Integer.Parse(InputTextBox4.Text)

                HomeForm.InventoryArray(IndexInteger).ItemSubTotal += HomeForm.InventoryArray(IndexInteger).ItemCount
                HomeForm.InventoryArray(IndexInteger).ItemGrandTotal += HomeForm.InventoryArray(IndexInteger).ItemSubTotal


            Else : IndexInteger += 1
            End If

        Loop

        InputTextBox1.Clear()
        InputTextBox2.Clear()
        InputTextBox3.Clear()
        InputTextBox4.Clear()
        InputComboBox2.SelectedIndex = -1
        InputComboBox3.SelectedIndex = -1
        InputComboBox4.SelectedIndex = -1
        With InputComboBox1
            .SelectedIndex = -1
            .Focus()
        End With

    End Sub





    Private Sub HomeButton_Click(sender As System.Object, e As System.EventArgs) Handles HomeButton.Click
        HomeForm.ShowDialog()
    End Sub

   
   


    Private Sub PrintDocument1_PrintPage(sender As System.Object, e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
        'handle print and print preview
        Dim PrintFont As New Font("Arial", 12)
        Dim HeadingFont As New Font("Arial", 14, FontStyle.Bold)
        Dim LineHeightSingle As Single = PrintFont.GetHeight + 2
        Dim Column1HorizontalLocationSingle As Single = e.MarginBounds.Left
        Dim VerticalPrintLocationSingle As Single = e.MarginBounds.Top
        Dim Column2HorizontalLocationSingle As Single = 300
        Dim Column3HorizontalLocationSingle As Single
        Dim PrintLineString As String
        Dim FontSizeF As New SizeF
        Dim FormattedPriceString As String

        'set up and display heading lines
        PrintLineString = "Transaction Report"
        e.Graphics.DrawString(PrintLineString, HeadingFont, Brushes.Black, Column2HorizontalLocationSingle,
                              VerticalPrintLocationSingle)
        PrintLineString = "by TBA Programing"
        VerticalPrintLocationSingle += LineHeightSingle
        e.Graphics.DrawString(PrintLineString, PrintFont, Brushes.Black, Column2HorizontalLocationSingle,
                              VerticalPrintLocationSingle)
        VerticalPrintLocationSingle += LineHeightSingle * 2

        'loop through the transactions
        For IndexInteger = 0 To 9
            'IndividualTransaction As HomeForm.InventoryStructure In HomeForm.InventoryArray

            'don't print if blank
            If HomeForm.InventoryArray(IndexInteger).ItemSubTotal <> 0 Then
                'set up a line
                'quantity
                e.Graphics.DrawString(HomeForm.InventoryArray(IndexInteger).Name, PrintFont, Brushes.Black,
                                      Column2HorizontalLocationSingle,
                                      VerticalPrintLocationSingle)

                'right-align the price
                FormattedPriceString = FormatNumber(HomeForm.InventoryArray(IndexInteger).ItemSubTotal)
                'measure string in this font
                FontSizeF = e.Graphics.MeasureString(FormattedPriceString, PrintFont)
                'subtract width of string from column position
                Column3HorizontalLocationSingle = 550 - FontSizeF.Width
                e.Graphics.DrawString(FormattedPriceString, PrintFont, Brushes.Black,
                                      Column3HorizontalLocationSingle,
                                      VerticalPrintLocationSingle)
                'increment the y position for the next line;Double space
                VerticalPrintLocationSingle += LineHeightSingle * 2

            End If
            IndexInteger += 1

        Next

    End Sub

    Private Sub TransactionReportButton_Click(sender As System.Object, e As System.EventArgs) Handles TransactionReportButton.Click
        PrintPreviewDialog1.Document = PrintDocument1
        PrintPreviewDialog1.ShowDialog()
    End Sub

End Class





And this is my Home Form


Public Class HomeForm
    Friend Structure InventoryStructure
        Dim Name As String
        Dim ItemCount As Integer
        Dim ItemSubTotal As Integer
        Dim ItemGrandTotal As Integer

    End Structure
    Friend InventoryArray(9) As InventoryStructure



    Private Sub InputFormButton_Click(sender As System.Object, e As System.EventArgs) Handles InputFormButton.Click
        InputForm.ShowDialog()
    End Sub

    

    Private Sub HomeForm_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        InventoryArray(0).Name = "Beans"
        InventoryArray(1).Name = "Rice"
        InventoryArray(2).Name = "Corn"
        InventoryArray(3).Name = "Pasta"
        InventoryArray(4).Name = "Cereal"
        InventoryArray(5).Name = "Mixed Vegitables"
        InventoryArray(6).Name = "Canned Meat"
        InventoryArray(7).Name = "Bread"
        InventoryArray(8).Name = "Tomatoes"
        InventoryArray(9).Name = "Misc"
    End Sub
End Class




Is This A Good Question/Topic? 0
  • +

Page 1 of 1