print loop help

Reply

Join Date: Nov 2008
Posts: 1
Reputation: DeathsBane is an unknown quantity at this point 
Solved Threads: 0
DeathsBane DeathsBane is offline Offline
Newbie Poster

print loop help

 
0
  #1
Nov 20th, 2008
im having issues with looping. This program needs the user to enter the upc and quantity then store the information then loop through the entered upc's and display the information. all i can get it to do is repeat the first entry 5 times. any advice would be helpful. I have included the entire code just because i'm not certain which part to post
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Public Class SalesForm
  2. 'Declare Module level variables & Hold UPC Code and total for 5 UPC's
  3. Private ArrayUPC(0 To 4) As String
  4. Private UPCPrice(0 To 4) As Decimal
  5. Private UPCDesc(0 To 4) As String
  6. Private UPCCode(0 To 4) As String
  7. Private PriceTotalDecimal(0 To 4) As Decimal
  8. Private GrandTotalDecimal(0 To 4) As Decimal
  9. Private ItemQuantityInteger(0 To 4) As Integer
  10. Private ItemDescString(0 To 4) As String
  11. Private IndexInteger As Integer = 0
  12.  
  13.  
  14.  
  15. Private Sub SalesForm_Load(ByVal sender As System.Object, _
  16. ByVal e As System.EventArgs) Handles MyBase.Load
  17. 'Initialize UPC Codes
  18. ArrayUPC(0) = "0921115150"
  19. ArrayUPC(1) = "2221001501"
  20. ArrayUPC(2) = "6652300415"
  21. ArrayUPC(3) = "0255541028"
  22. ArrayUPC(4) = "0921115141"
  23. UPCDesc(0) = "Dark Chocolate"
  24. UPCDesc(1) = "Mint Meltaways"
  25. UPCDesc(2) = "Chocolate Covered Cherries"
  26. UPCDesc(3) = "Malted Milk Balls"
  27. UPCDesc(4) = "chocolate Covered Raisins"
  28. UPCPrice(0) = 13.75D
  29. UPCPrice(1) = 14.1D
  30. UPCPrice(2) = 8.9D
  31. UPCPrice(3) = 5.99D
  32. UPCPrice(4) = 7.25D
  33.  
  34. End Sub
  35.  
  36. Private Sub AddButton_Click(ByVal sender As System.Object, _
  37. ByVal e As System.EventArgs) Handles AddButton.Click
  38. 'accumulate orders by upc
  39. Dim OrderedInteger As Integer
  40.  
  41. Dim FoundBoolean As Boolean = False
  42.  
  43. ' Lookup Input UPC Code to find subscript
  44. Try
  45. Do Until FoundBoolean Or IndexInteger > 4
  46. If UPCTextBox.Text = ArrayUPC(IndexInteger) Then
  47. 'add order to correct total
  48.  
  49. OrderedInteger = Integer.Parse(QuantityTextBox.Text)
  50. UPCCode(IndexInteger) += ArrayUPC(IndexInteger)
  51. ItemQuantityInteger(IndexInteger) += OrderedInteger
  52. PriceTotalDecimal(IndexInteger) += OrderedInteger * UPCPrice(IndexInteger)
  53. GrandTotalDecimal(IndexInteger) += PriceTotalDecimal(IndexInteger)
  54. ItemDescString(IndexInteger) = UPCDesc(IndexInteger)
  55. FoundBoolean = True
  56. QuantityTextBox.Clear()
  57. With UPCTextBox
  58. .Focus()
  59. .Clear()
  60. End With
  61. Else
  62. IndexInteger += 1
  63.  
  64. End If
  65. Loop
  66. If Not FoundBoolean Then
  67. MessageBox.Show("Enter a valid UPC", "Data Entry Error", _
  68. MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  69. With UPCTextBox
  70. .Focus()
  71. .SelectAll()
  72. End With
  73. End If
  74. Catch QuantityException As FormatException
  75. MessageBox.Show("Please enter the amount ordered in numeric form.", "Data Entry Error", _
  76. MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  77. With QuantityTextBox
  78. .Focus()
  79. .SelectAll()
  80. End With
  81. End Try
  82. End Sub
  83.  
  84. Private Sub ExitButton_Click(ByVal sender As System.Object, _
  85. ByVal e As System.EventArgs) Handles ExitButton.Click
  86. 'close application
  87. Dim ResponseDialogResult As DialogResult
  88.  
  89. 'double check to make sure to exit
  90. ResponseDialogResult = MessageBox.Show("Do you want to exit the program?", "Application Shut down", _
  91. MessageBoxButtons.YesNo, MessageBoxIcon.Question)
  92. If ResponseDialogResult = DialogResult.Yes Then
  93. Me.Close()
  94. End If
  95. End Sub
  96.  
  97. Private Sub PrintButton_Click(ByVal sender As System.Object, _
  98. ByVal e As System.EventArgs) _
  99. Handles PrintButton.Click
  100. 'print the report using print preview
  101.  
  102. PrintPreviewDialog1.Document = PrintDocument1
  103. PrintPreviewDialog1.ShowDialog()
  104.  
  105. End Sub
  106.  
  107. Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, _
  108. ByVal e As System.Drawing.Printing.PrintPageEventArgs) _
  109. Handles PrintDocument1.PrintPage
  110. 'Handle print and print preview
  111. Dim PrintFont As New Font("Arial", 12)
  112. Dim HeadingFont As New Font("Arial", 14, FontStyle.Bold)
  113. Dim LineHeightSingle As Single = PrintFont.GetHeight + 2
  114. Dim Column1HorizontalLocationSingle As Single = e.MarginBounds.Left
  115. Dim VerticalPrintlocationSingle As Single = e.MarginBounds.Top
  116. Dim Column2HorizontalLocationsingle As Single = 250
  117. Dim Column3HorizontalLocationSingle As Single = 400
  118. Dim Column4HorizontalLocationSingle As Single = 500
  119. Dim Column5HorizontallocationSingle As Single = 600
  120. Dim PrintLineString As String
  121. Dim FormattedQuantityString As String
  122. Dim LoopInteger As Integer
  123. Dim FoundBoolean As Boolean = False
  124.  
  125.  
  126.  
  127. 'Set up and Display Headings
  128. PrintLineString = "CandyCo Sales Report"
  129. e.Graphics.DrawString(PrintLineString, HeadingFont, _
  130. Brushes.Black, Column2HorizontalLocationsingle, _
  131. VerticalPrintlocationSingle)
  132. PrintLineString = "Programmed by Leo Lynch"
  133. VerticalPrintlocationSingle += LineHeightSingle
  134. e.Graphics.DrawString(PrintLineString, PrintFont, _
  135. Brushes.Black, Column2HorizontalLocationsingle, _
  136. VerticalPrintlocationSingle)
  137. VerticalPrintlocationSingle += LineHeightSingle * 2
  138. 'Set Up Tables
  139. e.Graphics.DrawString("UPC Code", PrintFont, Brushes.Black, _
  140. Column1HorizontalLocationSingle, VerticalPrintlocationSingle)
  141. e.Graphics.DrawString("Description", PrintFont, Brushes.Black, _
  142. Column2HorizontalLocationsingle, VerticalPrintlocationSingle)
  143. e.Graphics.DrawString("Price", PrintFont, Brushes.Black, _
  144. Column3HorizontalLocationSingle, VerticalPrintlocationSingle)
  145. e.Graphics.DrawString("Quantity", PrintFont, Brushes.Black, _
  146. Column4HorizontalLocationSingle, VerticalPrintlocationSingle)
  147. e.Graphics.DrawString("Total Cost", PrintFont, Brushes.Black, _
  148. Column5HorizontallocationSingle, VerticalPrintlocationSingle)
  149. VerticalPrintlocationSingle += LineHeightSingle * 2
  150.  
  151. FormattedQuantityString = Integer.Parse(ItemQuantityInteger(IndexInteger))
  152. IndexInteger = 0
  153. LoopInteger = 0
  154. 'Loop through the orders and UPC's
  155. For LoopInteger = 0 To 4
  156. If FormattedQuantityString <> "" Then
  157.  
  158. 'UPC Code
  159. e.Graphics.DrawString(UPCCode(IndexInteger), PrintFont, Brushes.Black, _
  160. Column1HorizontalLocationSingle, VerticalPrintlocationSingle)
  161. 'item description
  162. e.Graphics.DrawString(UPCDesc(IndexInteger), PrintFont, Brushes.Black, _
  163. Column2HorizontalLocationsingle, VerticalPrintlocationSingle)
  164. 'UPC Price
  165. e.Graphics.DrawString(UPCPrice(IndexInteger).ToString("C"), PrintFont, Brushes.Black, _
  166. Column3HorizontalLocationSingle, VerticalPrintlocationSingle)
  167. 'Amount Ordered
  168. e.Graphics.DrawString(ItemQuantityInteger(IndexInteger), PrintFont, Brushes.Black, _
  169. Column4HorizontalLocationSingle, VerticalPrintlocationSingle)
  170. 'Total Price of item
  171. e.Graphics.DrawString(PriceTotalDecimal(IndexInteger).ToString("C"), PrintFont, Brushes.Black, _
  172. Column5HorizontallocationSingle, VerticalPrintlocationSingle)
  173. VerticalPrintlocationSingle += LineHeightSingle * 2
  174. Else
  175. IndexInteger += 1
  176.  
  177. End If
  178.  
  179. Next LoopInteger
  180. 'Grand total
  181. e.Graphics.DrawString("Grand Total Price of Items Ordered", PrintFont, Brushes.Black, _
  182. Column1HorizontalLocationSingle, VerticalPrintlocationSingle)
  183. e.Graphics.DrawString(GrandTotalDecimal(IndexInteger).ToString("C"), PrintFont, Brushes.Green, _
  184. Column5HorizontallocationSingle, VerticalPrintlocationSingle)
  185. End Sub
  186. End Class
Reply With Quote Quick reply to this message  
Reply

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


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC