My print preview code isn't working. How do i make this work. Help will be greatly appreciated. thank you. Im trying to display my final checkout receipt, i wasn't able to paste a pic so it goes like this:
Customer ID: Title: Name: Bob Address: Car: Car ID: Upgrades: Cost: Product ID: Shop ID:
I want these in a column layout in the print preview screen. How would I do it?
Also I get a warning saying: Variable 'LineToPrints' has been used before and it could result in a null value.
Dim TitleFont As New Font("Courier New", 15, FontStyle.Bold)
Dim MyFont As New Font("Courier New", 12, FontStyle.Regular)
Dim MyFormat As String = "{0, 15}{1,15}"
Dim LineToPrints As String
Dim X As Integer
Dim Y As Integer
X = 15
FontHeight = MyFont.GetHeight(e.Graphics)
e.Graphics.DrawString("Checkout Receipt", TitleFont, Brushes.Black, X, Y)
For Y = 15 To 165 Step 15
Select Case Y
Case 30
LineToPrints = String.Format(MyFormat, "Customer ID: " & OneCustomer.CustomerID)
Case 45
LineToPrints = String.Format(MyFormat, "Title: " & OneCustomer.Title)
Case 60
LineToPrints = String.Format(MyFormat, "Name: " & Trim(OneCustomer.FirstName) & Trim(OneCustomer.LastName))
Case 75
LineToPrints = String.Format(MyFormat, "Address: " & OneCustomer.Address)
Case 90
LineToPrints = String.Format(MyFormat, "Car(s): " & OneBooking.Car)
Case 105
LineToPrints = String.Format(MyFormat, "Car ID: " & OneBooking.CarID)
Case 120
LineToPrints = String.Format(MyFormat, "Upgrades: " & OneBooking.Upgrade)
Case 135
LineToPrints = String.Format(MyFormat, "Cost: " & FormatCurrency(TotalCost))
Case 150
LineToPrints = String.Format(MyFormat, "Product ID: " & OneStock.ProductID)
Case 165
LineToPrints = String.Format(MyFormat, "ShopID: " & OneStock.ShopID)
End Select
e.Graphics.DrawString(LineToPrints, TitleFont, Brushes.Black, X, Y + 10)
e.Graphics.DrawString("Thank You For Purchasing At 'Ford Mustaang Selection Buyout'.", TitleFont, Brushes.Black, X, Y)
Next
You haven't detailed what error you're getting, or where it is occurring, but your format string has two placeholders, and you are only passing in one argument each time. Consider using
Dim MyFormat As String = "{0, 15}"
if you want the label and value to fit in 15 characters, orString.Format(MyFormat, "Product ID:", OneStock.ProductID)
if the label and value should be in separate columns.NB: Consider storing the field metadata in some data structure, e.g.
List(Of Tuple(Of String,Object))
:Then you can generate each line of the report as follows: