roughgod22 Level: Trainee
 Registered: 23-09-2009 Posts: 3
|
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
|