Programming in Visual Basic 2010 - 11 edition by Julia Case Bradley Ex 3.7 I try
ID: 3528952 • Letter: P
Question
Programming in Visual Basic 2010 - 11 edition by Julia Case Bradley Ex 3.7 I trying to get a format Exception Working but I cant get it work right!! Ugh... I can do the calculations and everything but the Format Exception doesnt work right? Here is my source code Option Strict On Public Class RentalCarForm 'Declare module-level variables and constants. Private BeginningInteger, EndingInterger, DayInteger As Integer Private TotalMilesDecimal, ChargeDecimal As Decimal Const TOTALMILES1_Decimal As Decimal = 0.12D Const Days_Decimal As Decimal = 15D Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitButton.Click 'Close the Program Me.Close() End Sub Private Sub PrintButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintButton.Click ' Print the Form PrintForm1.PrintAction = Printing.PrintAction.PrintToPreview PrintForm1.Print() End Sub Private Sub ClearButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearButton.Click 'Clear user Input from the form AddressTextBox.Clear() CityTextBox.Clear() StateTextBox.Clear() ZipTextBox.Clear() BeginningTextBox.Clear() EndingTextBox.Clear() DayTextBox.Clear() With NameTextBox .Clear() .Focus() End With End Sub Private Sub CalculateButton_Click(sender As System.Object, e As System.EventArgs) Handles CalculateButton.Click 'Calculate the miles driven and calulate the total charge. Format and Display answers. Dim BeginningInteger, EndingInteger, DaysInteger As Integer Dim TotalMilesDecimal, ChargeDecimal As Decimal Try BeginningInteger = Integer.Parse(BeginningTextBox.Text) EndingInteger = Integer.Parse(EndingTextBox.Text) DaysInteger = Integer.Parse(DayTextBox.Text) TotalMilesDecimal = Decimal.Parse(MilesSumLabel.Text) ChargeDecimal = Decimal.Parse(AmountChargeLabel.Text) Catch Ex As FormatException End Try Try 'Calculate Values TotalMilesDecimal = EndingInteger - BeginningInteger ChargeDecimal = (TotalMilesDecimal * TOTALMILES1_Decimal) + (DaysInteger * Days_Decimal) MilesSumLabel.Text = TotalMilesDecimal.ToString() AmountChargeLabel.Text = ChargeDecimal.ToString("C") Catch Ex As Exception End Try Try Catch EndingMiles As FormatException ' Show a numeric exception MessageBox.Show("Entry must be numeric", "Data Entry Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) With EndingTextBox .Focus() .SelectAll() End With End Try End Sub End Class I need the format exception to work when I dont put a numeric input in the beginning, ending, days text box.. 6 hours ago - 4 days left to answer.Explanation / Answer
Public Class RentalCarForm
'Declare module-level variables and constants.
Private BeginningInteger, EndingInterger, DayInteger As Integer
Private TotalMilesDecimal, ChargeDecimal As Decimal
Const TOTALMILES1_Decimal As Decimal = 0.12D
Const Days_Decimal As Decimal = 15D
Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitButton.Click
'Close the Program
Me.Close()
End Sub
Private Sub PrintButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintButton.Click
' Print the Form
PrintForm1.PrintAction = Printing.PrintAction.PrintToPreview
PrintForm1.Print()
End Sub
Private Sub ClearButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearButton.Click
'Clear user Input from the form
AddressTextBox.Clear()
CityTextBox.Clear()
StateTextBox.Clear()
ZipTextBox.Clear()
BeginningTextBox.Clear()
EndingTextBox.Clear()
DayTextBox.Clear()
With NameTextBox
.Clear()
.Focus()
End With
End Sub
Private Sub CalculateButton_Click(sender As System.Object, e As System.EventArgs) Handles CalculateButton.Click
'Calculate the miles driven and calulate the total charge. Format and Display answers.
Dim BeginningInteger, EndingInteger, DaysInteger As Integer
Dim TotalMilesDecimal, ChargeDecimal As Decimal
Try
BeginningInteger = Integer.Parse(BeginningTextBox.Text)
EndingInteger = Integer.Parse(EndingTextBox.Text)
DaysInteger = Integer.Parse(DayTextBox.Text)
TotalMilesDecimal = Decimal.Parse(MilesSumLabel.Text)
ChargeDecimal = Decimal.Parse(AmountChargeLabel.Text)
Catch Ex As FormatException
End Try
Try
'Calculate Values
TotalMilesDecimal = EndingInteger - BeginningInteger
ChargeDecimal = (TotalMilesDecimal * TOTALMILES1_Decimal) + (DaysInteger * Days_Decimal)
MilesSumLabel.Text = TotalMilesDecimal.ToString()
AmountChargeLabel.Text = ChargeDecimal.ToString("C")
Catch Ex As Exception
End Try
Try
Catch EndingMiles As FormatException
' Show a numeric exception
MessageBox.Show("Entry must be numeric", "Data Entry Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
With EndingTextBox
.Focus()
.SelectAll()
End With
End Try
End Sub
End Class
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.