-
Apr 5th, 2012, 01:26 PM
#1
Thread Starter
New Member
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!
-
Apr 5th, 2012, 01:57 PM
#2
Re: Print from a console app
can you post a screenshot of your console window + explain what you want to print?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Apr 5th, 2012, 02:00 PM
#3
Thread Starter
New Member
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.
-
Apr 5th, 2012, 02:02 PM
#4
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:
Imports System.Drawing.Printing
Module Module1
Private WithEvents PrintDocument1 As New PrintDocument
Sub Main()
Console.WriteLine("Print Output? [y/n]")
Dim answer As String = Console.ReadLine.ToLower
If answer = "y" Then
PrintDocument1.Print()
End If
End Sub
Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
e.Graphics.DrawString('etc
End Sub
End Module
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Apr 5th, 2012, 02:05 PM
#5
Thread Starter
New Member
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
-
Apr 5th, 2012, 02:18 PM
#6
Thread Starter
New Member
Re: Print from a console app
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|