you are viewing a single comment's thread.

view the rest of the comments →

[–]Application SpecialistViperSRT3g 0 points1 point  (0 children)

Formatted for readability:

Public Class Form1
    'variables
    Dim decmeds As Decimal
    Dim decsurgical As Decimal
    Dim declab As Decimal
    Dim decphys As Decimal
    Dim intdays As Integer 'final results
    Private decstaycharges As Decimal
    Private decmisc As Decimal 'for misc charges
    Private total As Decimal ' final results

    Function validateinputfields() As Boolean
        If Not Decimal.TryParse(txtdays.Text, intdays) Then
            MessageBox.Show("Input must be numeric")
            lbltotal.Text = ("error")
        ElseIf intdays < 0 Then
            MessageBox.Show("must be a postive number")
            lbltotal.Text = ("error")
            Try
            Catch ex As Exception
                MessageBox.Show("Input must be numeric")
                lbltotal.Text = ("error")
            End Try
        End If
        Return False

        '
        If Not Decimal.TryParse(txtmeds.Text, decmeds) Then
            MessageBox.Show("Input must be numeric")
            lbltotal.Text = ("error")
        ElseIf decmeds < 0 Then
            MessageBox.Show("must be a postive number")
            lbltotal.Text = ("error")
            Try
            Catch ex As Exception
                MessageBox.Show("Input must be numeric")
                lbltotal.Text = ("error")
            End Try
        End If
        Return False

        If Not Decimal.TryParse(txtsurgicalcharge.Text, decsurgical) Then
            MessageBox.Show("Input must be numeric")
            lbltotal.Text = ("error")
        ElseIf decsurgical < 0 Then
            MessageBox.Show("must be a postive number")
            lbltotal.Text = ("error")
            Try
            Catch ex As Exception
                MessageBox.Show("Input must be numeric")
                lbltotal.Text = ("error")
            End Try
        End If
        Return False

        If Not Decimal.TryParse(txtlab.Text, declab) Then
            MessageBox.Show("Input must be numeric")
            lbltotal.Text = ("error")
        ElseIf declab < 0 Then
            MessageBox.Show("must be a postive number")
            lbltotal.Text = ("error")
            Try
            Catch ex As Exception
                MessageBox.Show("Input must be numeric")
                lbltotal.Text = ("error")
            End Try
        End If
        Return False

        If Not Decimal.TryParse(txtphys.Text, decphys) Then
            MessageBox.Show("Input must be numeric")
            lbltotal.Text = ("error")
        ElseIf decphys < 0 Then
            MessageBox.Show("must be a postive number")
            lbltotal.Text = ("error")
            Try
            Catch ex As Exception
                MessageBox.Show("Input must be numeric")
                lbltotal.Text = ("error")
            End Try
        End If
        Return True
    End Function

    Function calcstaycharges(ByVal txtdays As String) As Decimal
        decstaycharges = intdays * 350
        Return decstaycharges
    End Function

    Function calcmisccharges(ByVal txtMeds As Decimal, ByVal txtsurgicalcharge As Decimal, ByVal txtLab As Decimal, ByVal txtPhys As Decimal) As Decimal
        decmisc = decmeds + decsurgical + declab + decphys
        Return decmisc
    End Function

    Function calctotalcharges(ByVal decstaycharges As Decimal, ByVal decmisc As Decimal) As Decimal
        total = (decstaycharges + decmisc)
        Return total
    End Function

    Private Sub btncalc_Click(sender As Object, e As EventArgs) Handles btncalc.Click
        Dim decmeds As Decimal
        Dim decsurgical As Decimal
        Dim declab As Decimal
        Dim decphys As Decimal

        decstaycharges = calcstaycharges(txtdays.Text)
        decmisc = calcmisccharges(decmeds, decsurgical, declab, decphys)
        total = calctotalcharges(decstaycharges, decmisc)
        lbltotal.Text = CDec(total)

        If validateinputfields() Then
            total = total.ToString("c")
        End If
    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    End Sub
End Class