Results 1 to 4 of 4

Thread: cant seem to get program to show correct price.

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2006
    Posts
    26

    cant seem to get program to show correct price.

    for some reason my program will not display the three different price levels for the coffee selections that i have input. i.e. when i select 1/4 lb, i should get 2.60, 1/2 lb 4.90 and full ib 8.75. i keep getting 2.60 regardless of the selection lb size i make. can anyone help. my code seems flawless up to this point. maybe i am off just a little somewhere.
    thanks.
    Code:
    Public Class bulkcoffeeForm
        'declare structure and module-level variabels
        Structure coffeesale
            Dim typestring As String
            Dim quantitystring As String
            Dim pricedecimal As Decimal
        End Structure
        Private transactioncoffeesale(20) As coffeesale
        Private numbertransactionsinteger As Integer
        Private pricedecimal(,) As Decimal = _
        {{2.6D, 2.9D, 3.25D}, {4.9D, 5.6D, 6.1D}, {8.75D, 9.75D, 11.25D}}
        Private selectedbuttonstring As String
    
        Private Sub exitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exitButton.Click
            'terminate the project
            Dim responsedialogresult As DialogResult
    
            responsedialogresult = MessageBox.Show("print the report?", _
    "terminate the application", MessageBoxButtons.YesNo, _
    MessageBoxIcon.Question)
            If responsedialogresult = DialogResult.Yes Then
                printButton_Click(sender, e)
            End If
            Me.Close()
    
        End Sub
    
        Private Sub clearButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clearButton.Click
            'remove the selection from the list and 
            'clear the price
    
            'select first radio button
            quarterpoundRadioButton.Select()
            'clear the coffee type selection
            coffeetypeComboBox.SelectedIndex = -1
            pricetextbox.clear()
        End Sub
    
        Private Sub printButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles printButton.Click
            'print the report using print preview
            With Me
                .PrintPreviewDialog1.Document = .printdocument1
                .PrintPreviewDialog1.ShowDialog()
            End With
        End Sub
    
        Private Sub quarterpoundRadioButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles quarterpoundRadioButton.CheckedChanged
            'save the name of the selected radio button
            'this procedure is executed each time any radio button is selected
    
            selectedbuttonstring = CType(sender, RadioButton).Name
    
        End Sub
    
        Private Sub findpriceButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles findpriceButton.Click
            'look up the price using the quantity and type
            Dim rowinteger, columninteger As Integer
            Dim salepricedecimal As Decimal
            With Me
                'allow only 20 transactiions
                If numbertransactionsinteger < 20 Then
                    columninteger = .coffeetypeComboBox.SelectedIndex
                    If columninteger <> -1 Then
                        'coffee selection made, determine quantity selected.
                        Select Case selectedbuttonstring
                            Case "quarterpoundradiobutton"
                                rowinteger = 0
                                transactioncoffeesale(numbertransactionsinteger).quantitystring _
                                = "quarter pound"
                            Case "halfpoundradiobutton"
                                rowinteger = 1
                                transactioncoffeesale(numbertransactionsinteger).quantitystring _
                                 = "half pound"
                            Case "fullpoundradiobutton"
                                rowinteger = 2
                                transactioncoffeesale(numbertransactionsinteger).quantitystring _
                                 = "full pound"
                            Case Else
                                'no selection made; use quarter pound.
                                rowinteger = 0
                                transactioncoffeesale(numbertransactionsinteger).quantitystring _
                                = "quarter pound"
                        End Select
                        'retrieve price of selection
                        salepricedecimal = pricedecimal(rowinteger, columninteger)
                        priceTextBox.Text = salepricedecimal.ToString("c")
                        'save this transaction
                        transactioncoffeesale(numbertransactionsinteger).typestring _
                          = .coffeetypeComboBox.Text
                        transactioncoffeesale(numbertransactionsinteger).pricedecimal _
                          = salepricedecimal
                        numbertransactionsinteger += 1
                    Else
                        MessageBox.Show("select the coffee type. ", "selection incomplete", _
                        MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                    End If
                Else
                    MessageBox.Show("sorry, only 20 transactions allowed.")
                End If
            End With
        End Sub
    
        Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
            'handles print and print preview
            Dim printfont As New Font("arial", 14, FontStyle.Bold)
            Dim headingfont As New Font("arial", 14, FontStyle.Bold)
            Dim lineheightsingle As Single = printfont.GetHeight + 2
            Dim column1horizontallocationsingle As Single = e.MarginBounds.Left
            Dim verticalprintlocationsingle As Single = e.MarginBounds.Top
            Dim column2horizontallocationsingle As Single = 300
            Dim column3horizontallocationsingle As Single
            Dim printlinestring As String
            Dim fontsizef As New SizeF
            Dim formattedpricestring As String
    
            'set up and display heading lines
            printlinestring = "R 'n R Coffee Sales"
            e.Graphics.DrawString(printlinestring, headingfont, _
            Brushes.Black, column2horizontallocationsingle, verticalprintlocationsingle)
            printlinestring = "by henry fair"
            verticalprintlocationsingle += lineheightsingle
            e.Graphics.DrawString(printlinestring, printfont, _
             Brushes.Black, column2horizontallocationsingle, verticalprintlocationsingle)
            verticalprintlocationsingle += lineheightsingle * 2
    
            'loop through the transactions
            For Each individualcoffeesale As coffeesale In transactioncoffeesale
                'dont print if blank
                If individualcoffeesale.quantitystring <> "" Then
                    'set up a line
    
                    'quantity
                    e.Graphics.DrawString(individualcoffeesale.quantitystring, printfont, _
                     Brushes.Black, column1horizontallocationsingle, verticalprintlocationsingle)
    
                    'type
                    e.Graphics.DrawString(individualcoffeesale.typestring, printfont, _
                   Brushes.Black, column2horizontallocationsingle, verticalprintlocationsingle)
    
                    'right-align the price
                    formattedpricestring = individualcoffeesale.pricedecimal.ToString("n")
                    'measure string in this font
                    fontsizef = e.Graphics.MeasureString(formattedpricestring, printfont)
                    'subtract width of string from column position
                    column3horizontallocationsingle = 560 - fontsizef.Width
                    e.Graphics.DrawString(formattedpricestring, printfont, _
                      Brushes.Black, column3horizontallocationsingle, verticalprintlocationsingle)
    
                    'increment the y position for the next line; double space
                    verticalprintlocationsingle += lineheightsingle * 2
                End If
            Next
        End Sub
    End Class

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: cant seem to get program to show correct price.

    Moved to VB.NET

  3. #3
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Lancashire UK
    Posts
    375

    Re: cant seem to get program to show correct price.

    You only seem to handle the 'quarterpoundRadioButton' event and as this seems to be the default selection I'd guess this would be why you only get the quarterpound result.
    If my post helps , please feel free to rate it

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Oct 2006
    Posts
    26

    Re: cant seem to get program to show correct price.

    ok, i will try to fix the quarterpound button
    thanks

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