Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27034

Try-Catch Block

$
0
0
Hey everyone my name is Mike and I am in a programming class but I am having a hard time getting my try-catch block to work with my coding. I can please have some help understanding it better also here is my code for the application:
Option Strict On

Public Class frmWeeklyPayCalculator

Const _cintMinutesInAnHour As Integer = 60I

Private Sub btnWeeklyPay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWeeklyPay.Click
' This event handler is executed when the user clicks the
' Weekly Pay button. It calculates and displays the weekly pay.

Dim strTotalMinutes As String
Dim intTotalMinutes As Integer
Dim strHourlyPayRate As String
Dim decHourlyPayRate As Decimal
Dim intTotalHoursWorked As Integer
Dim intTotalLeftoverMinutes As Integer
Dim strTotalWeeklyPay As String
Dim decTotalWeeklyPay As Decimal


' Get the input and convert to numberic
strTotalMinutes = txtTotalMinutes.Text
intTotalMinutes = Convert.ToInt32(strTotalMinutes)
strHourlyPayRate = txtHourlyPayRate.Text
decHourlyPayRate = Convert.ToDecimal(strHourlyPayRate)

'Calculate the Total cost and display
intTotalHoursWorked = intTotalMinutes \ 60
intTotalLeftoverMinutes = intTotalMinutes Mod 60
decTotalWeeklyPay = intTotalMinutes * decHourlyPayRate / _cintMinutesInAnHour

lblTotalHoursWorked.Text = intTotalHoursWorked.ToString()
lblTotalLeftoverMinutes.Text = intTotalLeftoverMinutes.ToString()
lblTotalWeeklyPay.Text = decTotalWeeklyPay.ToString("C")
btnClear.Focus()

Try
strTotalMinutes = txtTotalMinutes.Text
intTotalMinutes = Convert.ToInt32(strTotalMinutes)
strHourlyPayRate = txtHourlyPayRate.Text
decHourlyPayRate = Convert.ToDecimal(strHourlyPayRate)

lblTotalHoursWorked.Text = intTotalHoursWorked.ToString()
lblTotalLeftoverMinutes.Text = intTotalLeftoverMinutes.ToString()
lblTotalWeeklyPay.Text = decTotalWeeklyPay.ToString("C")

Catch ex As Exception

MessageBox.Show("no data entered, please enter data.")

End Try


End Sub

Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
' This event handler is executed when the user clicks the
' Clear button. It clears the total minutes worked text box
' and the Text property of Weekly Pay label. Then it sets
' the focus on the txtTotalMinutes Textbox object.

txtTotalMinutes.Clear()
txtHourlyPayRate.Clear()
txtTotalMinutes.Focus()

End Sub

Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
' Closes the window and terminates the application.

Close()

End Sub

Private Sub frmWeeklyPayCalculator_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

txtTotalMinutes.Clear()
txtHourlyPayRate.Clear()
txtTotalMinutes.Focus()

End Sub
End Class

Viewing all articles
Browse latest Browse all 27034

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>