I'm creating a program where an employer agrees to pay his employees with pennies. If the employees
agree they receive one penny the first day, two pennies the second day, four pennies the third day, and
counting double each day. My problem is when a user inputs 32 or more days the program prompts the user
with an error message reading "Your input must not exceed 31 days". That's perfect, it's what I want to
do. But my issue is when the user clicks OK on the error message the program still calculates the check
amount. I want to leave it blank with no money amount when the user clicks OK. Any suggestions?
Public Class Form1
Private Sub btnExit_Click(sender As System.Object, e As System.EventArgs) Handles btnExit.Click
'Exit program.
Me.Close()
End Sub
Private Sub btnCalculate_Click(sender As System.Object, e As System.EventArgs) Handles btnCalculate.Click
'Allow program to get total amount of pennies, then calculate to display amount.
Dim intNUM_DAYS As Integer 'The number of days possible to work.
Dim intMaxCount As Integer 'To hold the maximum count.
Dim decTotal As Decimal 'To hold total amount.
Dim intCount As Integer = 0 'Loop counter.
Dim dblTotal As Double = 0 'Accumulator,initialized to 0.
Dim intTotal As Integer 'Accumulator
Dim strInput As String 'To hold user input.
Dim dblNum As Double 'To hold a number.
'Dim cboAmountDays As Integer
Try
'Convert user selection of number of days worked to intNUM_DAYS.
intNUM_DAYS = CStr(cboAmountDays.Text)
'Add the numbers 1 through 31.
For intCount = 1 To 31
intTotal += intCount
Next
If cboAmountDays.Text > 31 Then
intTotal += intCount
MessageBox.Show("Your input must not exceed 31 days!..")
lblTotalCheckAmount.Text = String.Empty
End If
If Double.TryParse(cboAmountDays.Text, intNUM_DAYS) Then
dblTotal = (2 ^ intNUM_DAYS - 1) / (100)
End If
'Display amount to user.
lblTotalCheckAmount.Text = CStr(dblTotal.ToString("c"))
'Next
Catch
'Display error message.
MessageBox.Show("Please enter numeric value, try again.")
cboAmountDays.Text = String.Empty
cboAmountDays.Focus()
End Try
End Sub
Private Sub btnClear_Click(sender As System.Object, e As System.EventArgs) Handles btnClear.Click
'clear everything.
cboAmountDays.SelectedIndex = -1
cboAmountDays.Text = String.Empty
lblTotalCheckAmount.Text = String.Empty
cboAmountDays.Focus()
End Sub
End Class
agree they receive one penny the first day, two pennies the second day, four pennies the third day, and
counting double each day. My problem is when a user inputs 32 or more days the program prompts the user
with an error message reading "Your input must not exceed 31 days". That's perfect, it's what I want to
do. But my issue is when the user clicks OK on the error message the program still calculates the check
amount. I want to leave it blank with no money amount when the user clicks OK. Any suggestions?
Public Class Form1
Private Sub btnExit_Click(sender As System.Object, e As System.EventArgs) Handles btnExit.Click
'Exit program.
Me.Close()
End Sub
Private Sub btnCalculate_Click(sender As System.Object, e As System.EventArgs) Handles btnCalculate.Click
'Allow program to get total amount of pennies, then calculate to display amount.
Dim intNUM_DAYS As Integer 'The number of days possible to work.
Dim intMaxCount As Integer 'To hold the maximum count.
Dim decTotal As Decimal 'To hold total amount.
Dim intCount As Integer = 0 'Loop counter.
Dim dblTotal As Double = 0 'Accumulator,initialized to 0.
Dim intTotal As Integer 'Accumulator
Dim strInput As String 'To hold user input.
Dim dblNum As Double 'To hold a number.
'Dim cboAmountDays As Integer
Try
'Convert user selection of number of days worked to intNUM_DAYS.
intNUM_DAYS = CStr(cboAmountDays.Text)
'Add the numbers 1 through 31.
For intCount = 1 To 31
intTotal += intCount
Next
If cboAmountDays.Text > 31 Then
intTotal += intCount
MessageBox.Show("Your input must not exceed 31 days!..")
lblTotalCheckAmount.Text = String.Empty
End If
If Double.TryParse(cboAmountDays.Text, intNUM_DAYS) Then
dblTotal = (2 ^ intNUM_DAYS - 1) / (100)
End If
'Display amount to user.
lblTotalCheckAmount.Text = CStr(dblTotal.ToString("c"))
'Next
Catch
'Display error message.
MessageBox.Show("Please enter numeric value, try again.")
cboAmountDays.Text = String.Empty
cboAmountDays.Focus()
End Try
End Sub
Private Sub btnClear_Click(sender As System.Object, e As System.EventArgs) Handles btnClear.Click
'clear everything.
cboAmountDays.SelectedIndex = -1
cboAmountDays.Text = String.Empty
lblTotalCheckAmount.Text = String.Empty
cboAmountDays.Focus()
End Sub
End Class