Results 1 to 6 of 6

Thread: Print from a console app

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2012
    Posts
    8

    Print from a console app

    I have written a console app in visual studio basic 2010 that displays the output to the screen. I now need to be able to print the results. The books I have only cover window apps. Any help would be appreciated. Thank You!

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Print from a console app

    can you post a screenshot of your console window + explain what you want to print?

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2012
    Posts
    8

    Re: Print from a console app

    I don't want to print the window, I want to print a report. I want to use the results I get and make a report that I can print on the printer. I don't know if I am explaining this right.

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Print from a console app

    ok. this is the basic method. you need to add a reference to System.Drawing in your console app + then:

    vb Code:
    1. Imports System.Drawing.Printing
    2.  
    3. Module Module1
    4.  
    5.     Private WithEvents PrintDocument1 As New PrintDocument
    6.  
    7.     Sub Main()
    8.         Console.WriteLine("Print Output? [y/n]")
    9.         Dim answer As String = Console.ReadLine.ToLower
    10.  
    11.         If answer = "y" Then
    12.             PrintDocument1.Print()
    13.         End If
    14.  
    15.     End Sub
    16.  
    17.     Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
    18.         e.Graphics.DrawString('etc
    19.     End Sub
    20.  
    21. End Module

  5. #5

    Thread Starter
    New Member
    Join Date
    Mar 2012
    Posts
    8

    Re: Print from a console app

    Here is the sub that displays the output to the screen.
    Code:
     Sub Output(ByRef reorderLevel, ByRef shortagesPerCycle, ByRef noOfProducts, ByRef costReorder, ByRef costHolding, ByRef costShortage, ByRef costPurchase,
                   ByRef optReorderQty, ByRef dailyProductionRate, ByRef noOfOrdersPerYear, ByRef maxInv, ByRef totalCost, ByRef isCapCon,
                   ByRef setUpCost, ByRef noOfWorkDays, ByRef annualDemand, ByRef marginalCostOfSpace, ByRef costOfConInvSys, ByRef isJtProdProb, ByRef costOfJntProdProb,
                   ByRef percentDPR, ByRef productionRuns, ByRef totalProductionTime, ByRef productionCycleLength, ByRef totalSetUpTime, ByRef annualSetUpCost)
    
            Dim timeString As String
            Dim productCount As Integer
            Dim formattedAnnualSetUpCost As String
            Dim formattedCostReorder As String
            Dim formattedCostHolding As String
            Dim formattedCostShortage As String
            Dim formattedTimeString As String
            Dim formattedTotal As String
            Dim timeBetween As Double
            Dim marginalCostOfSetUpTime As Double = 10970.01
    
            Console.WriteLine()
            Console.WriteLine()
            Console.WriteLine("RESULTS")
            Console.WriteLine()
    
            If noOfProducts > 1 Then
                Console.WriteLine("Joint Product Analysis")
                Console.WriteLine()
            End If
    
            productCount = 0
    
            For productCount = 0 To noOfProducts - 1 Step +1
                Console.WriteLine("Product # " & productCount + 1)
                Console.WriteLine()
                Console.WriteLine("Optimum reorder quantity: " & optReorderQty(productCount))
                Console.WriteLine("Reorder level: " & reorderLevel(productCount))
                Console.WriteLine("This will result in " & shortagesPerCycle(productCount) & " shortages every cycle")
                Console.WriteLine("Annual Costs")
    
                If dailyProductionRate(productCount) <> 1 Then
                    formattedAnnualSetUpCost = "     Set Up " & "-"
                    formattedAnnualSetUpCost = formattedAnnualSetUpCost.PadRight(20)
                    Console.WriteLine(formattedAnnualSetUpCost & annualSetUpCost(productCount))
                Else
                    formattedCostReorder = "     Reorder " & "-"
                    formattedCostReorder = formattedCostReorder.PadRight(20)
                    Console.WriteLine(formattedCostReorder & costReorder(productCount))
                End If
    
                formattedCostHolding = "     Holding " & "-"
                formattedCostHolding = formattedCostHolding.PadRight(20)
                Console.WriteLine(formattedCostHolding & costHolding(productCount))
                formattedCostShortage = "     Shortage " & "-"
                formattedCostShortage = formattedCostShortage.PadRight(20)
                Console.WriteLine(formattedCostShortage & costShortage(productCount))
    
                If dailyProductionRate(productCount) <> 0 Then
                    timeString = "Purchase "
                Else
                    timeString = "Production "
                End If
    
                formattedTimeString = "     " & timeString & "- "
                formattedTimeString = formattedTimeString.PadRight(20)
                Console.WriteLine(formattedTimeString & costPurchase(productCount))
                Console.WriteLine()
                formattedTotal = "     Total " & "- "
                formattedTotal = formattedTotal.PadRight(20)
                Console.WriteLine(formattedTotal & totalCost(productCount))
                Console.WriteLine()
                Console.WriteLine()
    
                If dailyProductionRate(productCount) <> 1 Then
                    timeString = "production runs"
                Else
                    timeString = "orders"
                End If
    
                If dailyProductionRate(productCount) <> 1 Then
    
                    Console.WriteLine("Time for " & timeString & " is " & productionRuns(productCount) & " days")
                    Console.WriteLine()
                End If
    
                If dailyProductionRate(productCount) <> 1 Then
                    dailyProductionRate(productCount) = 1 - percentDPR(productCount)
                End If
    
                timeBetween = Math.Round(((optReorderQty(productCount) * noOfWorkDays) * dailyProductionRate(productCount) / annualDemand(productCount)), 2)
    
                Console.WriteLine("The time between " & timeString & " is " & timeBetween & " days")
                Console.WriteLine()
                Console.WriteLine("The number of " & timeString & " each year is " & noOfOrdersPerYear(productCount))
                Console.WriteLine()
                Console.WriteLine("The maximum inventory level is " & maxInv(productCount))
                Console.WriteLine()
    
                If productCount = noOfProducts - 1 Then
                    If isCapCon = True Then
                        Console.WriteLine()
                        Console.WriteLine("Capacity Constraint Results")
                        Console.WriteLine()
                        Console.WriteLine("The marginal cost of space is: " & marginalCostOfSpace)
                        Console.WriteLine()
                        Console.WriteLine("The total annual cost of the constrained inventory system is: " & costOfConInvSys)
                        Console.WriteLine()
                    End If
    
                    If isJtProdProb = True Then
                        Console.WriteLine()
                        Console.WriteLine("The total annual cost of the joint production lot runs is: " & costOfJntProdProb)
                        Console.WriteLine()
                        Console.WriteLine("The total time for production is " & totalProductionTime & " days out of " & noOfWorkDays & " working days")
                        Console.WriteLine()
                        Console.WriteLine("The time taken for set ups each year is " & totalSetUpTime & " days")
                        Console.WriteLine()
                        Console.WriteLine("Each production cycle is " & productionCycleLength & " days")
                        Console.WriteLine()
                        Console.WriteLine("The marginal cost of set up times is " & marginalCostOfSetUpTime)
                    End If
                End If
            Next productCount
    
        End Sub

  6. #6

    Thread Starter
    New Member
    Join Date
    Mar 2012
    Posts
    8

    Re: Print from a console app

    Thank You

Posting Permissions

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



Click Here to Expand Forum to Full Width