EDN Admin
Well-known member
i cannot figure out why my summary button is not working for a piecework program i am creating for class.. here are the codes if anyone can diagnose my problem and help me solve it, it would be awesome. Public Class MainForm
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 ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitButton.Click
Me.Close()
End Sub
Private Sub ClearButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearButton.Click
AmountEarnedTextBox.Clear()
PiecesTextBox.Clear()
With NameTextBox
.Clear()
.Focus()
End With
NameTextBox.Enabled = True
PiecesTextBox.Enabled = True
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
Private Sub SummaryButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SummaryButton.Click
declare local variables.
Dim AverageDecimal As Decimal
Dim MessageString As String
check totaldecimal to clear current order.
If totalpaydecimal <> 0 Then
Make sure the last order is counted
ClearAllButton_Click(sender, e)
End If
if customercount larger than 0, generate summary report.
If workercountinteger > 0 Then
Calculate the average
AverageDecimal = totalpaydecimal / workercountinteger
concatenate the message string.
MessageString = "Number of Pieces: " & workercountinteger.ToString & Environment.NewLine & Environment.NewLine & "Total Sales: " & totalpaydecimal.ToString("C") & Environment.NewLine & Environment.NewLine & "Average Sale: " & AverageDecimal.ToString("C")
MessageBox.Show(MessageString, "Pieces Produced Summary", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
No customers visited yet
MessageString = "No production data to report. "
MessageBox.Show(MessageString, "Pieces Produced Summary", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub
Private Sub CalculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalculateButton.Click
NameTextBox.Enabled = False
PiecesTextBox.Enabled = False
ClearButton.Enabled = True
ClearAllButton.Enabled = True
SummaryButton.Enabled = True
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(PiecesTextBox.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 employees pay
AmountEarnedTextBox.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 PiecesTextBox
.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 PiecesTextBox
.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
End Class
View the full article
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 ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitButton.Click
Me.Close()
End Sub
Private Sub ClearButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearButton.Click
AmountEarnedTextBox.Clear()
PiecesTextBox.Clear()
With NameTextBox
.Clear()
.Focus()
End With
NameTextBox.Enabled = True
PiecesTextBox.Enabled = True
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
Private Sub SummaryButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SummaryButton.Click
declare local variables.
Dim AverageDecimal As Decimal
Dim MessageString As String
check totaldecimal to clear current order.
If totalpaydecimal <> 0 Then
Make sure the last order is counted
ClearAllButton_Click(sender, e)
End If
if customercount larger than 0, generate summary report.
If workercountinteger > 0 Then
Calculate the average
AverageDecimal = totalpaydecimal / workercountinteger
concatenate the message string.
MessageString = "Number of Pieces: " & workercountinteger.ToString & Environment.NewLine & Environment.NewLine & "Total Sales: " & totalpaydecimal.ToString("C") & Environment.NewLine & Environment.NewLine & "Average Sale: " & AverageDecimal.ToString("C")
MessageBox.Show(MessageString, "Pieces Produced Summary", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
No customers visited yet
MessageString = "No production data to report. "
MessageBox.Show(MessageString, "Pieces Produced Summary", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub
Private Sub CalculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalculateButton.Click
NameTextBox.Enabled = False
PiecesTextBox.Enabled = False
ClearButton.Enabled = True
ClearAllButton.Enabled = True
SummaryButton.Enabled = True
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(PiecesTextBox.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 employees pay
AmountEarnedTextBox.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 PiecesTextBox
.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 PiecesTextBox
.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
End Class
View the full article