Tuesday, June 28, 2016

MINI CALCULATOR PROGRAM IN VB.NET

Source code
Public Class frmCalculator
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub

    Private Sub btnresult_Click(sender As Object, e As EventArgs) Handles btnresult.Click
        If frmvaildate() Then
            Dim fnum, snum, result As Double
            Dim opt As String

            fnum = Double.Parse(txtfnumber.Text)
            snum = Double.Parse(txtsnum.Text)
            opt = txtopt.Text

            Select Case (opt)
                Case "+"
                    result = fnum + snum
                Case "-"
                    result = fnum - snum
                Case "*"
                    result = fnum * snum
                Case "/"
                    If snum = 0 Then
                        MessageBox.Show("No is not  div by zero")
                        Return
                    Else
                        result = fnum / snum
                    End If
                Case Else
                    MessageBox.Show("Invalid Operation")
                    txtopt.Clear()
                    txtopt.Focus()
                    Return
            End Select
            txtresult.Text = result.ToString()
        End If

    End Sub
    Public Function frmvaildate() As Boolean
        Dim flag As Boolean = True
        If (txtfnumber.Text.Length = 0) Then
            MessageBox.Show("Enter First Number")
            txtfnumber.Focus()
            flag = False
        ElseIf Not (IsNumeric(txtfnumber.Text))
            MessageBox.Show("Enter only numeric value")
            txtfnumber.Clear()
            txtfnumber.Focus()
            flag = False
        ElseIf txtsnum.Text.Length = 0
            MessageBox.Show("Enter Second Number")
            txtsnum.Focus()
            flag = False
        ElseIf Not (IsNumeric(txtsnum.Text))
            MessageBox.Show("Enter only numeric value")
            txtsnum.Clear()
            txtsnum.Focus()
            flag = False
        ElseIf txtopt.Text.Length = 0
            MessageBox.Show("Enter Operator")
            txtopt.Focus()
            flag = False
        End If
        Return flag
    End Function
    Private Sub txtfnumber_KeyDown(sender As Object, e As KeyEventArgs) Handles txtfnumber.KeyDown
        If (Integer.Parse(e.KeyCode()) = 13) Then
            txtsnum.Focus()
        End If
    End Sub
    Private Sub txtsnum_KeyDown(sender As Object, e As KeyEventArgs) Handles txtsnum.KeyDown
        If (Integer.Parse(e.KeyCode()) = 13) Then
            txtopt.Focus()
        End If
    End Sub
    Private Sub txtopt_KeyDown(sender As Object, e As KeyEventArgs) Handles txtopt.KeyDown
        If (Integer.Parse(e.KeyCode()) = 13) Then
            btnresult.Focus()
        End If
    End Sub

    Private Sub btnclear_Click(sender As Object, e As EventArgs) Handles btnclear.Click
        clear()
    End Sub
    Public Sub clear()
        txtfnumber.Clear()
        txtsnum.Clear()
        txtopt.Clear()
        txtresult.Clear()
        txtfnumber.Focus()
    End Sub
End Class


Sunday, June 19, 2016

Attendance Management System Program Using Array in Vb.net

Module Module1

    Sub Main()
        Dim studname() As String = {"Rakesh", "Mukesh", "Suresh", "Anil", "Vijay", "Prince"}
        Dim rollno() As Integer = {1001, 1002, 1003, 1004, 1005, 1006}
        Dim attendance(6) As Integer
        Dim counter As Integer = 0
        Dim attenstatus As String
        Dim attencounter As Integer = 0
        Dim totalstudent As Integer = 1
        Dim totabs, totpre As Integer
        totabs = 0
        totpre = 0
        While (totalstudent <= 6)
            Console.Write("Enter Studnet Roll No:-")
            Dim studroll As Integer = Integer.Parse(Console.ReadLine())
            Console.Write(counter)
            For Each studrollno As Integer In rollno
                If studrollno = studroll Then
                    Console.Write("Studnet Name:-" & studname(counter) & vbNewLine)
                    Console.Write("Enter P for Present and A for Absent:-")
                    attenstatus = Console.ReadLine()
                    If (attenstatus = "P") Then
                        attendance(attencounter) = 1
                        attencounter = attencounter + 1
                    ElseIf (attenstatus = "A")
                        attendance(attencounter) = 0
                        attencounter = attencounter + 1
                    End If
                End If
                counter = counter + 1
            Next
            counter = 0
            totalstudent = totalstudent + 1
        End While

        Console.Write("Student Name" & vbTab & "Attendance" & vbNewLine)
        For attendcounter As Integer = 0 To 5
            If attendance(attendcounter) = 0 Then
                totabs = totabs + 1
            ElseIf attendance(attendcounter) = 1
                totpre = totpre + 1
            End If
            Console.Write(studname(attendcounter) & vbTab & vbTab & attendance(attendcounter) & vbNewLine)
        Next
        Console.Write("Total Present Student=" & totpre & vbNewLine & "Total Absent Student=" & totabs)
    End Sub

End Module