Printing HELP

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2007
Posts: 7
Reputation: Rockstar4cs is an unknown quantity at this point 
Solved Threads: 0
Rockstar4cs Rockstar4cs is offline Offline
Newbie Poster

Printing HELP

 
0
  #1
Nov 16th, 2007
I want the print button below to print out whatever the user orders and not the entire order list. The List is steam read into the list box I made. My problem is when I click the print button it displays all the products in the print preview instead of the item ordered. I tried selected item for the print button thinking it would only show the selected item in the print preview with no luck could I get some help please?



  1. Public Class Form1
  2. Structure ProductRecord
  3. Dim strProduct As String
  4. Dim intQuantity As Integer
  5. Dim sngPrice As Single
  6. End Structure
  7. Dim ProRec(10) As ProductRecord
  8. Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
  9. ' End the application
  10. Me.Close()
  11. End Sub
  12. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  13. Dim intIndex As Integer
  14. Dim strFileNameIn As String
  15.  
  16. Try
  17. btnPrint.Enabled = False
  18. Dim Reader As New IO.StreamReader("products.txt")
  19. strFileNameIn = "products.txt"
  20. intIndex = 0
  21.  
  22. Do Until Reader.Peek = -1
  23. With Reader
  24. ProRec(intIndex).strProduct = .ReadLine()
  25. ProRec(intIndex).intQuantity = CInt(.ReadLine())
  26. ProRec(intIndex).sngPrice = CSng(.ReadLine())
  27. lstProducts.Items.Add(ProRec(intIndex).strProduct)
  28. End With
  29.  
  30. intIndex += 1
  31.  
  32. Loop
  33. lstProducts.SelectedIndex = 0
  34. Reader.Close()
  35. Catch ex As Exception
  36. MessageBox.Show(ex.Message, "Error in Reading file", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  37. End Try
  38. End Sub
  39.  
  40. Private Sub lstProducts_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstProducts.SelectedIndexChanged
  41. lblPrice.Text = ("$") & CStr((ProRec(lstProducts.SelectedIndex).sngPrice))
  42. End Sub
  43.  
  44. Private Sub btnOrder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOrder.Click
  45. Dim outputfile As StreamWriter
  46.  
  47. 'If lstProducts.SelectedIndex = -1 Then
  48. 'MsgBox("Select a prouduct", MsgBoxStyle.Critical)
  49. ' Else
  50. ' Select Case CStr(lstProducts.SelectedIndex)
  51. ' Case CStr(0) = nudQuantity.Value = 5
  52. ' MsgBox("Select a prouduct", MsgBoxStyle.Critical)
  53. ' Case CStr(1)
  54. ' MsgBox("Select a prouduct", MsgBoxStyle.Critical)
  55. ' Case CStr(2)
  56. ' MsgBox("Select a prouduct", MsgBoxStyle.Critical)
  57. ' End Select
  58. 'End If
  59.  
  60. outputfile = AppendText("C:outputfile.txt")
  61. lblItems.Text = ProRec(lstProducts.SelectedIndex).strProduct
  62. lblCost.Text = ("$") & CStr(CSng(lblPrice.Text) * nudQuantity.Value)
  63. outputfile.WriteLine(lblItems.Text)
  64. outputfile.WriteLine(lblCost.Text)
  65. outputfile.Close()
  66. btnOrder.Enabled = False
  67. btnPrint.Enabled = True
  68.  
  69.  
  70. End Sub
  71.  
  72. Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
  73. PrintPreviewSelected.Document = PrintSelected
  74. PrintPreviewSelected.PrintPreviewControl.Zoom = 1
  75. PrintPreviewSelected.ShowDialog()
  76. End Sub
  77.  
  78. Private Sub PrintPreviewDialog1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintPreviewProducts.Load
  79.  
  80. End Sub
  81.  
  82. Private Sub btnReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReport.Click
  83. PrintPreviewProducts.Document = PrintReport
  84. PrintPreviewProducts.PrintPreviewControl.Zoom = 1
  85. PrintPreviewProducts.ShowDialog()
  86. End Sub
  87.  
  88. Private Sub PrintReport_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintReport.PrintPage
  89. Dim sngX As Single
  90. Dim sngY As Single
  91. Dim fntPrintFont As New Font("Arial", 12)
  92. Dim sngLineHeight As Single = fntPrintFont.GetHeight + 2
  93. Dim intListIndex As Integer
  94.  
  95. sngX = e.MarginBounds.Left
  96. sngY = e.MarginBounds.Top
  97. 'print heading
  98. e.Graphics.DrawString("Iventory Report", fntPrintFont, Brushes.Black, sngX, sngY)
  99. sngY += sngLineHeight
  100. sngY += sngLineHeight
  101. e.Graphics.DrawString("Products Quantity Price", fntPrintFont, Brushes.Black, sngX, sngY)
  102. sngY += sngLineHeight
  103. sngY += sngLineHeight
  104. 'display list of Products
  105. For intListIndex = 0 To lstProducts.Items.Count - 1
  106. e.Graphics.DrawString(CStr(lstProducts.Items(intListIndex)), fntPrintFont, Brushes.Black, sngX, sngY)
  107. sngY += sngLineHeight
  108. Next
  109. sngY += sngLineHeight
  110. sngY += sngLineHeight
  111. End Sub
  112.  
  113. Private Sub PrintSelected_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintSelected.PrintPage
  114. Dim sngX As Single
  115. Dim sngY As Single
  116. Dim fntPrintFont As New Font("Arial", 12)
  117. Dim sngLineHeight As Single = fntPrintFont.GetHeight + 2
  118. Dim intListIndex As Integer
  119.  
  120. sngX = e.MarginBounds.Left
  121. sngY = e.MarginBounds.Top
  122. 'print heading
  123. e.Graphics.DrawString("Order", fntPrintFont, Brushes.Black, sngX, sngY)
  124. sngY += sngLineHeight
  125. sngY += sngLineHeight
  126. e.Graphics.DrawString("Products Cost", fntPrintFont, Brushes.Black, sngX, sngY)
  127. sngY += sngLineHeight
  128. sngY += sngLineHeight
  129. 'display list of Products
  130. For intListIndex = 0 To lstProducts.Items.Count - 1
  131. e.Graphics.DrawString(CStr(lstProducts.Items(intListIndex)), fntPrintFont, Brushes.Black, sngX, sngY)
  132. sngY += sngLineHeight
  133. Next
  134. sngY += sngLineHeight
  135. sngY += sngLineHeight
  136. End Sub
  137. End Class
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 7
Reputation: Rockstar4cs is an unknown quantity at this point 
Solved Threads: 0
Rockstar4cs Rockstar4cs is offline Offline
Newbie Poster

Re: Printing HELP

 
0
  #2
Nov 17th, 2007
I'm working on this project for class I steam read theses products into a list box on my form I made in VB2005. I'm having an issue when I go to print tho. My first problem is that I have a list box a print button and a report button and also and exit button. When the User Orders one of my products I made it so the print button is enabled and prints out the product selected so far tho instead of printing out just what the user selected it prints out all the products. Could you please look at me code and tell me If I'm doing this right I'll post the whole thing but again the print statement is the only thing I need an answer to if somone would please look at it thanks. Again I'm just posting the whole code so you can see my logic the line in Print Selected is the problem I said print selected item and it gave me an error thanks alot again.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 7
Reputation: Rockstar4cs is an unknown quantity at this point 
Solved Threads: 0
Rockstar4cs Rockstar4cs is offline Offline
Newbie Poster

Re: Printing HELP

 
0
  #3
Nov 17th, 2007
  1. e.Graphics.DrawString(CStr(lstProducts.Items(intListIndex.SelectedIndex)), fntPrintFont, Brushes.Black, sngX, sngY)sngY += sngLineHeight

This line right here seeems to be giving me the most trouble I put selectedIndex in so that when I click print it would only show the product selected. But VB keeps giving me an error message saying.

'Selected index' is not a member of integer'
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 122
Reputation: manal is an unknown quantity at this point 
Solved Threads: 17
manal's Avatar
manal manal is offline Offline
Junior Poster

Re: Printing HELP

 
0
  #4
Nov 18th, 2007
Dim intListIndex As Integer
what i understand from your code that intListIndex is integer , so you can not write
intListIndex.SelectedIndex
to print only what the user select try this
  1. e.Graphics.DrawString(lstProducts.SelectedItem, fntPrintFont, Brushes.Black, sngX, sngY)
Last edited by manal; Nov 18th, 2007 at 5:52 am.
"give only what u willing to receive "
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 7
Reputation: Rockstar4cs is an unknown quantity at this point 
Solved Threads: 0
Rockstar4cs Rockstar4cs is offline Offline
Newbie Poster

Re: Printing HELP

 
0
  #5
Nov 19th, 2007
Well that Works with the products but I want the price too the price is declared up above and is read with the code.
Dim sngPrice As Single
I tried this to print out the price
  1. e.Graphics.DrawString(CStr(lblCost.Text(lstProducts.SelectedIndex)), fntPrintFont, Brushes.Black, sngX, sngY)
it didnt work
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the VB.NET Forum
Thread Tools Search this Thread



Tag cloud for VB.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC