borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2010 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (PLEASE DEBUG)Next Topic (Pls help, cell-objects, excel,) New Topic New Poll Post Reply
AndreaVB Forum : VB General : vb newbie has problem
Poster Message
roughgod22
Level: Trainee

Registered: 23-09-2009
Posts: 3

Ads by Lake Quincy Media
icon vb newbie has problem

newbie has a problem, i keep getting a "no data to summarize" error, code follows:

Public Class Form1
    'dim module level variables
    Const EXTRA_LARGE_DECIMAL = 0.65D
    Const LARGE_DECIMAL = 0.6D
    Const MEDIUM_DECIMAL = 0.55D
    Const SMALL_DECIMAL = 0.5D

    'delare module level variables for summary
    Private totalpaydecimal, avgpaydecimal As Decimal
    Private workercountinteger, totalpiecesinteger As Integer

    Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click

    End Sub

    Private Sub CalculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalculateButton.Click
        Dim quantityinteger As Integer
        Dim paydecimal, paydecimal1 As Decimal
        Dim messagestring As String

        'Calculate pay
        If nameTextBox.Text <> "" Then 'Name has been entered

            Try
                'Convert the quantity
                quantityinteger = Integer.Parse(quantityTextBox.Text)

                'Number of pieces must be greater the zero
                If quantityinteger > 0 Then
                    'Determine the correct pay rate
                    Select Case quantityinteger
                        Case Is >= 600
                            paydecimal = EXTRA_LARGE_DECIMAL
                        Case 400 To 599
                            paydecimal = LARGE_DECIMAL
                        Case 200 To 399
                            paydecimal = MEDIUM_DECIMAL
                        Case 1 To 199
                            paydecimal = SMALL_DECIMAL

                    End Select

                    'Perform calculations and accumulate all values
                    paydecimal1 = Convert.ToDecimal(paydecimal * quantityinteger)
                    totalpaydecimal += paydecimal1

                    'Display this employee's pay
                    payTextBox.Text = paydecimal1.ToString("c")
                    totalpayTextBox.Text = totalpaydecimal.ToString("c")


                Else
                    'Zero was entered
                    messagestring = "Please enter a number greater than zero."
                    MessageBox.Show(messagestring, "Data Entry Error", _
                        MessageBoxButtons.OK, MessageBoxIcon.Information)
                    With quantityTextBox
                        .Focus()
                        .SelectAll()
                    End With
                End If

            Catch QuantityException As FormatException
                'Quantity must be numeric
                messagestring = "Please input the number of pieces."
                MessageBox.Show(messagestring, "Input Error", _
                    MessageBoxButtons.OK, MessageBoxIcon.Error)
                With quantityTextBox
                    .Focus()
                    .SelectAll()
                End With
            Catch AnException As Exception
                MessageBox.Show("Error: " & AnException.Message)
            End Try

        Else
            'No entry in name field
            messagestring = "Please enter an employee name."
            MessageBox.Show(messagestring, "Missing Data", _
            MessageBoxButtons.OK, MessageBoxIcon.Information)
            nameTextBox.Focus()
        End If
    End Sub

    Private Sub summaryButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles summaryButton.Click
        'Calculate the average pay and display the totals
        Dim messagestring As String
        Dim avgpaydecimal As Decimal
        Dim workercountinteger As Integer
        Dim paydecimal1 As Decimal

        If workercountinteger > 0 Then
            'Clear textboxes and labels
            'clearButton_Click(sender, e)
            Try
                'Calculate average pay
                avgpaydecimal = paydecimal1 / workercountinteger

                'Concatenate the message string
                messagestring = "Total Pieces:  " & totalpiecesinteger.ToString _
                 & Environment.NewLine & Environment.NewLine _
                 & "Total Pay:  " & totalpaydecimal.ToString("C") _
                 & Environment.NewLine & Environment.NewLine _
                 & "Average Amount Earned:  " & avgpaydecimal.ToString("C") _
                 & Environment.NewLine & Environment.NewLine _
                 & "Number of Workers:  " & workercountinteger.ToString("N0")

                MessageBox.Show(messagestring, "Piecework Pay Summary", _
                        MessageBoxButtons.OK, MessageBoxIcon.Information)
            Catch
                messagestring = "Error in Calculations."
                MessageBox.Show(messagestring, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
                Me.quantityTextBox.Focus()
            End Try

        Else
            messagestring = "No data to summarize."
            MessageBox.Show(messagestring, "Piecework Pay Summary", MessageBoxButtons.OK, _
                MessageBoxIcon.Information)
            Me.nameTextBox.Focus()
        End If

    End Sub

    Private Sub clearButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clearButton.Click
        'Clear textboxes for a new worker

        payTextBox.Clear()
        quantityTextBox.Clear()
        With nameTextBox
            .Clear()
            .Focus()
        End With

    End Sub

    Private Sub clearallbutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clearallbutton.Click
        'Clear all information
        Dim ReturnDialogResult As DialogResult
        Dim MessageString As String

        'Confirm clear of current order
        MessageString = "Clear all data?"
        ReturnDialogResult = MessageBox.Show(MessageString, "Reset", _
         MessageBoxButtons.YesNo, MessageBoxIcon.Question, _
         MessageBoxDefaultButton.Button2)

        If ReturnDialogResult = DialogResult.Yes Then    'User clicked the yes buttin
            clearButton_Click(sender, e)     'Clear all fields
            'Clear summary totals
            workercountinteger = 0
            totalpiecesinteger = 0
            totalpaydecimal = 0
        End If

    End Sub

any help would greatly be appreciated

23-09-2009 at 10:07 PM
View Profile Send Email to User Show All Posts | Quote Reply
GeoffS
Level: VB Lord


Registered: 29-09-2004
Posts: 606
icon Re: vb newbie has problem

You have declared the Variable "workercountinteger"  both at Module level and also within the summaryButton_Click Sub. This means that within the summaryButton_Click Sub any reference to the Variable "workercountinteger" will reference the one delared within the Sub, the Module level Variable is ignored. Since you have not assigned a value to the Sub level Variable "If workercountinteger > 0 Then" will always move to the "Else" statement as it IS ZERO.
Also, you do not appear to have assigned a value to the Module level "workercountinteger" anywhere in the code you have posted, so removing the Sub level declaration for the variable will still make no difference as workercountinteger still equals ZERO.



____________________________
multi-tasking - the ability to hang more than one app. at the same time.

24-09-2009 at 02:54 PM
View Profile Send Email to User Show All Posts | Quote Reply
roughgod22
Level: Trainee

Registered: 23-09-2009
Posts: 3
icon Re: vb newbie has problem

Thanks GeoffS you are a life saver, works like a charm

Ads by Lake Quincy Media
24-09-2009 at 08:11 PM
View Profile Send Email to User Show All Posts | Quote Reply
internet13444
Level: Trainee

Registered: 27-09-2009
Posts: 1
icon Re: vb newbie has problem

Welcome!

[Edited by internet13444 on 27-09-2009 at 07:53 AM GMT]

27-09-2009 at 07:51 AM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : VB General : vb newbie has problem
Previous Topic (PLEASE DEBUG)Next Topic (Pls help, cell-objects, excel,) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2010 Andrea Tincaniborder