Sunday, July 3, 2016

Calculate Rupee Program In Vb.Net

Calculate Rupee Program Source Code
Public Class frmcalrupess
    Private Sub btncalrup_Click(sender As Object, e As EventArgs) Handles btncalrup.Click
        If txtrupess.Text.Length = 0 Then
            MsgBox("Enter Rupess", MsgBoxStyle.Critical, "Alert Message")
            txtrupess.Focus()
            reini()
            rmvhighlight()
            Return
        ElseIf Not IsNumeric(txtrupess.Text) Then
            MsgBox("Enter Only Numeric Value", MsgBoxStyle.Critical, "Alert Message")
            txtrupess.Clear()
            txtrupess.Focus()
            reini()
            rmvhighlight()
            Return
        ElseIf Integer.Parse(txtrupess.Text) = 0 Then
            MsgBox("Enter Rupees is greater than zero", MsgBoxStyle.Critical, "Alert Message")
            txtrupess.Clear()
            txtrupess.Focus()
            reini()
            rmvhighlight()
            Return
        ElseIf Integer.Parse(txtrupess.Text) < 0 Then
            MsgBox("Enter only postive value", MsgBoxStyle.Critical, "Alert Message")
            txtrupess.Clear()
            txtrupess.Focus()
            reini()
            rmvhighlight()
            Return
        End If
        calrup()
    End Sub
    Public Sub calrup()
        Try
            Dim non() As Integer = {1000, 500, 100, 50, 20, 10, 5, 2, 1}

            Dim min, strresrup, tnon As Double
            tnon = 0
            strresrup = Math.Round(Double.Parse(txtrupess.Text), 0)
            txtrupess.Text = strresrup.ToString
            min = strresrup
            While strresrup <> 0
                For counter As Integer = 0 To non.Length - 1
                    If (non(counter) <= min) Then
                        strresrup = strresrup - non(counter)
                        tnon = tnon + 1
                        Exit For
                    End If
                Next
                min = strresrup
            End While


            Dim strnon(tnon - 1) As Integer

            tnon = 0
            strresrup = Math.Round(Double.Parse(txtrupess.Text), 0)

            min = strresrup
            While strresrup <> 0
                For counter As Integer = 0 To non.Length - 1
                    If (non(counter) <= min) Then
                        strnon(tnon) = non(counter)
                        strresrup = strresrup - non(counter)
                        tnon = tnon + 1
                        Exit For
                    End If
                Next
                min = strresrup
            End While

            reini()
            For counter As Integer = 0 To tnon - 1
                If (strnon(counter) = 1000) Then
                    txtthousand.Text = Integer.Parse(txtthousand.Text) + 1
                ElseIf (strnon(counter) = 500) Then
                    txtfhun.Text = Integer.Parse(txtfhun.Text) + 1
                ElseIf (strnon(counter) = 100) Then
                    txthun.Text = Integer.Parse(txthun.Text) + 1
                ElseIf (strnon(counter) = 50) Then
                    txtfifty.Text = Integer.Parse(txtfifty.Text) + 1
                ElseIf (strnon(counter) = 20) Then
                    txttwenty.Text = Integer.Parse(txttwenty.Text) + 1
                ElseIf (strnon(counter) = 10) Then
                    txtten.Text = Integer.Parse(txtten.Text) + 1
                ElseIf (strnon(counter) = 5) Then
                    txtfive.Text = Integer.Parse(txtfive.Text) + 1
                ElseIf (strnon(counter) = 2) Then
                    txttwo.Text = Integer.Parse(txttwo.Text) + 1
                ElseIf (strnon(counter) = 1) Then
                    txtone.Text = Integer.Parse(txtone.Text) + 1
                End If
            Next
            highlight()
        Catch ex As Exception

        End Try
    End Sub
    Public Sub reini()
        txtthousand.Text = "0"
        txtfhun.Text = "0"
        txthun.Text = "0"
        txtfifty.Text = "0"
        txttwenty.Text = "0"
        txtten.Text = "0"
        txtfive.Text = "0"
        txttwo.Text = "0"
        txtone.Text = "0"
    End Sub
    Public Sub highlight()
        If Integer.Parse(txtthousand.Text) > 0 Then
            txtthousand.BackColor = Color.Blue
            txtthousand.ForeColor = Color.White
        Else
            txtthousand.BackColor = Color.White
        End If
        If Integer.Parse(txtfhun.Text) > 0 Then
            txtfhun.BackColor = Color.Blue
            txtfhun.ForeColor = Color.White
        Else
            txtfhun.BackColor = Color.White
        End If
        If Integer.Parse(txthun.Text) > 0 Then
            txthun.BackColor = Color.Blue
            txthun.ForeColor = Color.White
        Else
            txthun.BackColor = Color.White
        End If
        If Integer.Parse(txtfifty.Text) > 0 Then
            txtfifty.BackColor = Color.Blue
            txtfifty.ForeColor = Color.White
        Else
            txtfifty.BackColor = Color.White
        End If
        If Integer.Parse(txttwenty.Text) > 0 Then
            txttwenty.BackColor = Color.Blue
            txttwenty.ForeColor = Color.White
        Else
            txttwenty.BackColor = Color.White
        End If
        If Integer.Parse(txtten.Text) > 0 Then
            txtten.BackColor = Color.Blue
            txtten.ForeColor = Color.White
        Else
            txtten.BackColor = Color.White
        End If
        If Integer.Parse(txtfive.Text) > 0 Then
            txtfive.BackColor = Color.Blue
            txtfive.ForeColor = Color.White
        Else
            txtfive.BackColor = Color.White
        End If
        If Integer.Parse(txttwo.Text) > 0 Then
            txttwo.BackColor = Color.Blue
            txttwo.ForeColor = Color.White
        Else
            txttwo.BackColor = Color.White
        End If
        If Integer.Parse(txtone.Text) > 0 Then
            txtone.BackColor = Color.Blue
            txtone.ForeColor = Color.White
        Else
            txtone.BackColor = Color.White
        End If
    End Sub
    Public Sub rmvhighlight()

        txtthousand.BackColor = Color.White
        txtthousand.ForeColor = Color.Black


        txtfhun.BackColor = Color.White
        txtfhun.ForeColor = Color.Black



        txthun.BackColor = Color.White
        txthun.ForeColor = Color.Black


        txtfifty.BackColor = Color.White
        txtfifty.ForeColor = Color.Black
       

        txttwenty.BackColor = Color.White
        txttwenty.ForeColor = Color.Black
       

        txtten.BackColor = Color.White
        txtten.ForeColor = Color.Black
       

        txtfive.BackColor = Color.White
        txtfive.ForeColor = Color.Black
       

        txttwo.BackColor = Color.White
        txttwo.ForeColor = Color.Black
       

        txtone.BackColor = Color.White
        txtone.ForeColor = Color.Black
       
    End Sub

    Private Sub frmcalrupess_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub
End Class

Click Here To Download Output File For Calculate Rupee Program

3 comments: