sample of visual basic application with source codes

 Student Profile using ADD, EDIT, DELETE
controls in Visual Basic .Net
 
and I just want to share some of my knowledge in 
coding Visual basic application .
I suggest that you create a Graphical User Interface before you start coding...
(the picture above is a screenshot of my simple application)
Here is the codes :

Imports MyLibraryFunctions.Mydata
Imports MyLibraryFunctions.LoadData
Imports MyLibraryFunctions.CommClasses
Imports MyLibraryFunctions.MyFunctions
''' <summary>
''' pREPARED FOR:


Public Class StudentProfile

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        'Dim InsertInfo As List(Of IPersonals) = New List(Of IPersonals)
        'InsertInfo.Add(New InsertData(Me.txtFname.Text, Me.txtMname.Text, Me.txtLname.Text, _
        '                              Me.txtAddress.Text, Me.txtEadd.Text, Me.txtMobNo.Text, Me.txtTelNo.Text))
        Dim Disable As Functions = New Functions
        Dim Insert As InsertData = (New InsertData(Me.txtFname.Text, Me.txtMname.Text, Me.txtLname.Text, _
                                      Me.txtAddress.Text, Me.txtEadd.Text, Me.txtMobNo.Text, Me.txtTelNo.Text))
        If Me.txtFname.Text = String.Empty And txtMobNo.Text = String.Empty And txtTelNo.Text = String.Empty Then

            MsgBox("Please Fill the ff Important details", MsgBoxStyle.Information, "PROFILE OF STUDENT")

        Else

            Insert.MyData()
        End If

        Disable.DisableString(Me)
        Disable.DisableButton(Me)
        Me.btnAdd.Focus()
        Me.txtSearch.Enabled = True
        Me.btnAdd.Enabled = True
        Me.btnEdit.Enabled = True
        Me.btnLoad.Enabled = True
        Me.btnExit.Enabled = True
        Disable.ClearTextBox(Me)
    End Sub

    Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click

        Dim Disable As Functions = New Functions
        Dim Update As UpdateData = New UpdateData(Me.txtFname.Text, Me.txtMname.Text, Me.txtLname.Text, _
                                      Me.txtAddress.Text, Me.txtEadd.Text, Me.txtMobNo.Text, Me.txtTelNo.Text)
        If Me.txtFname.Text = String.Empty And txtMobNo.Text = String.Empty And txtTelNo.Text = String.Empty Then

            MsgBox("No Data!", MsgBoxStyle.Information, "PROFILE")

        Else

            Update.MyData()

        End If


        Disable.DisableString(Me)
        Disable.DisableButton(Me)
        Me.txtSearch.Enabled = True
        Me.btnAdd.Enabled = True
        Me.btnEdit.Enabled = True
        Me.btnLoad.Enabled = True
        Me.btnExit.Enabled = True
        Disable.ClearTextBox(Me)
    End Sub

    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click

        Dim Disable As Functions = New Functions
        Dim Delete As DeleteData = New DeleteData(Me.txtFname.Text, Me.txtMname.Text, Me.txtLname.Text, _
                                     Me.txtAddress.Text, Me.txtEadd.Text, Me.txtMobNo.Text, Me.txtTelNo.Text)
        Delete.MyData()

        Disable.DisableString(Me)
        Disable.DisableButton(Me)
        Me.btnAdd.Enabled = True
        Me.btnEdit.Enabled = True
        Me.btnLoad.Enabled = True
        Me.txtSearch.Enabled = True
        Me.btnExit.Enabled = True
        Disable.ClearTextBox(Me)
    End Sub

    Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click

        Dim Load As SearchFromTable = New SearchFromTable

        With Me.DataGridView1
            .DataSource = Load.GetMyData _
            ("Select *" _
             + " From tblInfo Where Fname='" & Trim(Me.txtSearch.Text) & "'" _
             + " or Lname='" & Trim(Me.txtSearch.Text) & "'")
        End With

    End Sub

    Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoad.Click

        Dim Load As SearchFromTable = New SearchFromTable

        With Me.DataGridView1
            .DataSource = Load.GetMyData _
            ("Select * From tblInfo")
        End With

    End Sub

    Private Sub PhoneBook_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

        Dim response As MsgBoxResult
        response = MsgBox("Are you sure you want to close this application?", _
                          vbYesNo + vbExclamation + vbApplicationModal + _
                          vbDefaultButton2, "Close confirmation")
        If response = MsgBoxResult.Yes Then
            Me.Visible = False
            Me.Dispose()
            Me.Close()
            End
        ElseIf response = MsgBoxResult.No Then
            e.Cancel = True
            Exit Sub
        End If

    End Sub

    Private Sub PhoneBook_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim Disable As Functions = New Functions
        Disable.DisableString(Me)
        Disable.DisableButton(Me)
        Me.btnExit.Enabled = True
        Me.btnAdd.Enabled = True
        Me.btnEdit.Enabled = True
        Me.btnLoad.Enabled = True
        Me.txtSearch.Enabled = True
    End Sub

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        Dim Enable As Functions = New Functions
        Enable.EnabledString(Me)
        Me.btnEdit.Enabled = False
        Me.btnSave.Enabled = True
        Me.btnCancel.Enabled = True
        Me.BtnPrint.Enabled = True
        Me.BtnClear.Enabled = True
        Me.btnEdit.Enabled = True
        Me.btnLoad.Enabled = True
    End Sub

    Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click
        Dim Enable As Functions = New Functions
        Enable.EnabledString(Me)
        Me.btnAdd.Enabled = False
        Me.btnUpdate.Enabled = True
        Me.btnDelete.Enabled = True
        Me.btnCancel.Enabled = True
        Me.BtnPrint.Enabled = True
        Me.BtnClear.Enabled = True
    End Sub
    ''' <summary>
    ''' You can use DoubleClick or Enter in Datagridview to Load the data
    ''' in textboxes.
    ''' </summary>
    Private Sub DataGridView1_CellEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEnter
        Dim GridRow As DataGridViewRow = DataGridView1.CurrentRow
        txtFname.Text = CStr(GridRow.Cells.Item("Fname").Value)
        txtMname.Text = CStr(GridRow.Cells.Item("Mname").Value)
        txtLname.Text = CStr(GridRow.Cells.Item("Lname").Value)
        txtAddress.Text = CStr(GridRow.Cells.Item("Address").Value)
        txtMobNo.Text = CStr(GridRow.Cells.Item("MobNo").Value)
        txtTelNo.Text = CStr(GridRow.Cells.Item("TelNo").Value)
        txtEadd.Text = CStr(GridRow.Cells.Item("EAdd").Value)
    End Sub

    Private Sub DataGridView1_CellMouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseDoubleClick
        Dim GridRow As DataGridViewRow = DataGridView1.CurrentRow
        txtFname.Text = CStr(GridRow.Cells.Item("Fname").Value)
        txtMname.Text = CStr(GridRow.Cells.Item("Mname").Value)
        txtLname.Text = CStr(GridRow.Cells.Item("Lname").Value)
        txtAddress.Text = CStr(GridRow.Cells.Item("Address").Value)
        txtMobNo.Text = CStr(GridRow.Cells.Item("MobNo").Value)
        txtTelNo.Text = CStr(GridRow.Cells.Item("TelNo").Value)
        txtEadd.Text = CStr(GridRow.Cells.Item("EAdd").Value)
    End Sub
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks>Note: To Load datas in Datagridview Click Load Button</remarks>
    Private Sub txtSearch_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtSearch.KeyPress
        If Asc(e.KeyChar) = Keys.Enter Then
            btnSearch_Click(Nothing, Nothing)
            e.Handled = True
        End If
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Dim Disable As Functions = New Functions
        Disable.ClearTextBox(Me)
        Disable.DisableString(Me)
        Disable.DisableButton(Me)
        Me.btnAdd.Enabled = True
        Me.btnEdit.Enabled = True
        Me.btnLoad.Enabled = True
        Me.txtSearch.Enabled = True
        Me.btnExit.Enabled = True
        Me.BtnClear.Enabled = True
    End Sub

    Private Sub txtMobNo_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtMobNo.KeyPress
        Dim NumOlny As Functions = New Functions
        e.Handled = NumOlny.TrapKey(Asc(e.KeyChar))
    End Sub

    Private Sub txtTelNo_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtTelNo.KeyPress
        Dim NumOlny As Functions = New Functions
        e.Handled = NumOlny.TrapKey(Asc(e.KeyChar))
    End Sub


    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnPrint.Click
        'pRINT form
        PrintForm1.PrintAction = Printing.PrintAction.PrintToPreview
        PrintForm1.Print()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnClear.Click
        txtFname.Clear()
        txtLname.Clear()
        txtAddress.Clear()
        txtEadd.Clear()
        txtMname.Clear()
        txtTelNo.Clear()
        txtMobNo.Clear()
    End Sub
End Class





  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • RSS

4 comments:

Unknown said...

You have done a very good job. Thank you very much.Can I get the original VB.net Student profile file,please.

Unknown said...

hi, can I ask for the whole file?please...badly need it.thank you so much.

Unknown said...

hi! can I get the original Vb.net student profile please .I need it for my project..ASAP

bobby said...

very impressive

Post a Comment