Cracken
Member
Hi
I have built a small overtime calculator application which works fine, however on some calculations you get an infinity number which just displays infinity as text and not a number.
Could anyone please advise me how to shorten this NaN result to display a number 4 decimal places long and not infinity text.
Thanks for any help in advance.
Code:
Public Class Form1
Dim mth As Single
Dim quart As Single = 1.25
Dim half As Single = 1.5
Dim doub As Integer = 2
Dim hrs As Integer
Dim slr As Integer
Dim ctr As Integer
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
If txtHours.Text & txtSalary.Text & txtContract.Text = "" Then
lblDetailsError.Text = "Enter overtime hours, gross salary and contract Hours"
ElseIf txtHours.Text & txtSalary.Text = "" Then
lblDetailsError.Text = "Enter number of overtime hours worked and gross salary"
ElseIf txtHours.Text & txtContract.Text = "" Then
lblDetailsError.Text = "Enter number of overtime hours worked and contract hours"
ElseIf txtSalary.Text & txtContract.Text = "" Then
lblDetailsError.Text = "Enter gross salary and contract hours"
ElseIf txtSalary.Text & txtHours.Text = "" Then
lblDetailsError.Text = "Please enter gross salary and overtime hours worked"
ElseIf txtHours.Text = "" Then
lblDetailsError.Text = "Enter number of overtime hours worked"
ElseIf txtSalary.Text = "" Then
lblDetailsError.Text = "Enter the gross salary"
ElseIf txtContract.Text = "" Then
lblDetailsError.Text = "Enter the contract hours"
Else
Convert.ToInt32(txtHours.Text)
Convert.ToInt32(txtSalary.Text)
Convert.ToInt32(txtContract.Text)
lblDetailsError.Text = ""
CheckRate()
End If
End Sub
Private Sub CheckRate()
If rbTimeQuarter.Checked = True Then
CalculateQuart()
ElseIf rbTimeHalf.Checked = True Then
CalculateHalf()
ElseIf rbDoubleTime.Checked = True Then
CalculateDouble()
Else
lblRateError.Text = "Please select an overtime rate"
End If
End Sub
Private Sub CalculateQuart()
hrs = txtHours.Text
slr = txtSalary.Text
ctr = txtContract.Text
mth = slr / 52 / ctr * hrs * quart
txtResults.Text = mth.ToString()
lblRateError.Text = ""
Uncheck()
End Sub
Private Sub CalculateHalf()
hrs = txtHours.Text
slr = txtSalary.Text
mth = slr / 52 / ctr * hrs * half
txtResults.Text = mth.ToString()
lblRateError.Text = ""
Uncheck()
End Sub
Private Sub CalculateDouble()
hrs = txtHours.Text
slr = txtSalary.Text
mth = slr / 52 / ctr * hrs * doub
txtResults.Text = mth.ToString()
lblRateError.Text = ""
Uncheck()
End Sub
Private Sub Uncheck()
If rbDoubleTime.Checked = True Then
rbDoubleTime.Checked = False
ElseIf rbTimeHalf.Checked = True Then
rbTimeHalf.Checked = False
ElseIf rbTimeQuarter.Checked = True Then
rbTimeQuarter.Checked = False
End If
End Sub
Private Sub CloseToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseToolStripMenuItem.Click
Me.Close()
End Sub
End Class
Mark
I have built a small overtime calculator application which works fine, however on some calculations you get an infinity number which just displays infinity as text and not a number.
Could anyone please advise me how to shorten this NaN result to display a number 4 decimal places long and not infinity text.
Thanks for any help in advance.
Code:
Public Class Form1
Dim mth As Single
Dim quart As Single = 1.25
Dim half As Single = 1.5
Dim doub As Integer = 2
Dim hrs As Integer
Dim slr As Integer
Dim ctr As Integer
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
If txtHours.Text & txtSalary.Text & txtContract.Text = "" Then
lblDetailsError.Text = "Enter overtime hours, gross salary and contract Hours"
ElseIf txtHours.Text & txtSalary.Text = "" Then
lblDetailsError.Text = "Enter number of overtime hours worked and gross salary"
ElseIf txtHours.Text & txtContract.Text = "" Then
lblDetailsError.Text = "Enter number of overtime hours worked and contract hours"
ElseIf txtSalary.Text & txtContract.Text = "" Then
lblDetailsError.Text = "Enter gross salary and contract hours"
ElseIf txtSalary.Text & txtHours.Text = "" Then
lblDetailsError.Text = "Please enter gross salary and overtime hours worked"
ElseIf txtHours.Text = "" Then
lblDetailsError.Text = "Enter number of overtime hours worked"
ElseIf txtSalary.Text = "" Then
lblDetailsError.Text = "Enter the gross salary"
ElseIf txtContract.Text = "" Then
lblDetailsError.Text = "Enter the contract hours"
Else
Convert.ToInt32(txtHours.Text)
Convert.ToInt32(txtSalary.Text)
Convert.ToInt32(txtContract.Text)
lblDetailsError.Text = ""
CheckRate()
End If
End Sub
Private Sub CheckRate()
If rbTimeQuarter.Checked = True Then
CalculateQuart()
ElseIf rbTimeHalf.Checked = True Then
CalculateHalf()
ElseIf rbDoubleTime.Checked = True Then
CalculateDouble()
Else
lblRateError.Text = "Please select an overtime rate"
End If
End Sub
Private Sub CalculateQuart()
hrs = txtHours.Text
slr = txtSalary.Text
ctr = txtContract.Text
mth = slr / 52 / ctr * hrs * quart
txtResults.Text = mth.ToString()
lblRateError.Text = ""
Uncheck()
End Sub
Private Sub CalculateHalf()
hrs = txtHours.Text
slr = txtSalary.Text
mth = slr / 52 / ctr * hrs * half
txtResults.Text = mth.ToString()
lblRateError.Text = ""
Uncheck()
End Sub
Private Sub CalculateDouble()
hrs = txtHours.Text
slr = txtSalary.Text
mth = slr / 52 / ctr * hrs * doub
txtResults.Text = mth.ToString()
lblRateError.Text = ""
Uncheck()
End Sub
Private Sub Uncheck()
If rbDoubleTime.Checked = True Then
rbDoubleTime.Checked = False
ElseIf rbTimeHalf.Checked = True Then
rbTimeHalf.Checked = False
ElseIf rbTimeQuarter.Checked = True Then
rbTimeQuarter.Checked = False
End If
End Sub
Private Sub CloseToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseToolStripMenuItem.Click
Me.Close()
End Sub
End Class
Mark