Tuesday, February 4, 2014

Hoe to Create/Establish a VBasic--MS Access Database Connection

STEPS
After Designing your form and naming your controls, follow the below steps:

**Double click on any area on your form to display the code window
Outside your class scope, import both system.Data and system.Data.oledb
~~~~~~~~~~~~~~~~~~~                                                                                  
Imports System.Data                                                                         
Imports System.Data.OleDb 
~~~~~~~~~~~~~~~~~~~                                                                                      
**Now, inside your class but outside any method/function, declare a new connection, command and connection string
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~                                                            
Dim Conn As New OleDbConnection     
Dim Conn_command As New OleDbCommand                                           
Dim Conn_String = "   ' your connection string "                                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~

**Next, under your forms load event, set and open the connection             ~~~~~~~~~~~~~~~~~~~~~~                                                                          
Conn.ConnectionString = Conn_String
Conn.Open()
~~~~~~~~~~~~~~~~~~~~~~                                                                                                       
**Lastly, set your command text, command type, connection AND execute your sql statement                                                                           
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Conn_command.CommandText = " Sql statement "
Conn_command.CommandType = CommandType.Text
Conn_command.Connection = Conn
Conn_command.ExecuteNonQuery()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Still don't get it, see example below
------------------------------
Windows form ~> frm1.vb
------------------------------














First name text box is named txtFirstName
Last name text box is named txtLastName
Address text box is named txtAddress
Phone text box is named txtPhone
Update button is named BtnUpdate

Source Code ~> Designed using vb 2010
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' import statements ~> Outside the class scope 
Imports System.Data
Imports System.Data.OleDb
' class begins
Public Class frm_main   
    
    ' NOW Inside the class BUT outside any method scope                                                                  Creat a new Oledb Connection = Access Dbase connection
    Dim Conn As New OleDbConnection

    ' Creat a new Oledb Command
    Dim Conn_command As New OleDbCommand

    'Connection String = The database connection string
    Dim Conn_String = "Provider=Microsoft.Jet.OLEDB.4.0;Data               Source=C:\DBaseFiles\Employee.mdb"
    Private Sub frm1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        ' Set the connection String
        Conn.ConnectionString = Conn_String

        'Open the connection 
        Conn.Open()
    End Sub

     ' Click event
    Private Sub BtnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnUpdate.Click

        Dim Query As String
        Query = "Insert into Emp_PersonalDetails values (' " & txtFirstName.Text & " ', ' " & txtLastName.Text & " ', ' " & txtAddress.Text & " ', ' " & txtPhone.Text & " ')"
        Conn_command.CommandText = Query
        'Set the command type
        Conn_command.CommandType = CommandType.Text
        'Set the connection
        Conn_command.Connection = Conn
        'Execute Query
        Conn_command.ExecuteNonQuery()

         ' Display message     
         Dim msg As String
        msg = MessageBox.Show("Record Updated Succesfully", "Employee DBase")

    End Sub
End Class

Source code screen shot
~~~~~~~~~~~~~~~~~

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
Below is the database view after a record is added/updated:







Still don't get it, watch the below video 

Who is a Software Developer?

A software developer is a person who is responsible to make specialized computer software for a client, or for himself OR herself. 
There are three kinds of software developers:
1. Computer Programmers
2. Software Developers, User Applications
3. Software Developers, Systems
As a software developer in an organization, your job will involve some or more of the following:
• Designing software
• Programming
• Installation
• Configuration
• Customization
• Specification
• Requirements analysis
• Development and refinement of simulations or prototypes
• Feasibility and cost–benefit analysis
• Testing
• Maintenance
In other words, in this technical world, the work of a software developer is extremely important. It also carries good financial benefits.

Monday, January 27, 2014

Factorial (n!), Permutation (nPr) and Combination (nCr) Calculator. "Java Code Snippet"

Factorials { n! ~> pronounced n factorial } are used to compute permutations (nPr) and combinations (nCr). A factorial is the result of multiplying a given number of consecutive integers from 1 to the given number. It is written with the exclamation sign: n! and it is defined as
0! = 1
1! = 1
2! = 2 x 1 = 2
3! = 3 x 2 x 1 = 6
4! = 4 x 3 x 2 x 1 = 24
5! 
5! = 5 x 4 x 3 x 2 x 1 = 120 ...~> and so on   

-----------------------------------
Source Code for calculating n!
-----------------------------------
   import static java.lang.System.out;
      import java.util.Scanner;

     public class factorial
     {  
           public static void main(String[] args)
           {
                       out.print(" Enter your value : ");

                          Scanner in = new Scanner(System.in);
                             int input = in.nextInt();

                         int fac = 1;
                         for(int num = input; num>=1; num--)
                         {
                     fac = fac * num;
                      }
             
            out.printf(" The factorial of %d = %d" , input, fac);
             out.println();
   }
       }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Permutation ~> nPr = n!/(n-r)!
In the context of counting problems, Permutations is the arrangements where the order is important and repetitions or recurrence is not allowed. The number of permutations of n distinct points taken r at a time is written as nPr. Because the number of objects is being arranged cannot exceed total number available. There are n! (n factorial) permutations of n symbols. A r-permutation of n symbols is a permutation of r of them. There are n!/(n - r)! different r-permutations of n symbols. A permutations represented by nPr and calculated from the formula nPr = n!/(n - r)!

------------------------------------
Source Code for calculating nPr
------------------------------------
   import static java.lang.System.out;
      import java.util.Scanner;

      public class nPr
      {
                 // static variables n for the value of n and ...
static int n,r, n_Sub_r;

           public static void main(String[] args)
           {
                     out.print(" Enter the value of n = ");

                       Scanner in1 = new Scanner(System.in);
                             int input1 = in1.nextInt();

                             // saving a copy of input1 which is = n
                             n = input1;

                              // calculating n factorial

                              int nFac = 1;

                              for(int num1 = n; num1 >=1; num1--)
                               {
                                nFac = nFac * num1;
        }

                         out.print("\n Enter the value of r = ");

               Scanner in2 = new Scanner(System.in);
               int input2 = in2.nextInt();

                // saving a copy of input2 which is = r
                                             r = input2;

         // calculating the value of n - r as n_Sub_r
                                        n_Sub_r = (n - r);

                         // calculating n - r factorial
                                 int n_rFac = 1;

         for(int num2 = n_Sub_r; num2 >=1; num2--)
         {
          n_rFac = n_rFac * num2;
         }

                         // calculating (n!/(n-r)!)

                             int result = (nFac / n_rFac);

                           out.printf("\n %dP%d = %d\n\n" , n ,r, result);
          }
           }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Combination~> nCr = n!/(n-r)!r!
Combinations is a method of selecting several items or symbols out of a larger group or a data set, where an order does not matter. The Combination represented by nCr and calculated from the formula nCr = n!/(r!(n - r)!). Each r combination can be arranged in r! different ways. Then the number of r-permutations is equal to the number of r combinations times r!

------------------------------------
Source Code for calculating nCr
------------------------------------
import static java.lang.System.out;
      import java.util.Scanner;

      public class nCr
      {
                 // static variables n for the value of n and ...
static int n,r, n_Sub_r;

           public static void main(String[] args)
           {
                    out.print(" Enter the value of n = ");

                       Scanner in1 = new Scanner(System.in);
                             int input1 = in1.nextInt();

                             // saving a copy of input1 which is = n
                                   n = input1;

                              // calculating n factorial
                                  int nFac = 1;

                              for(int num1 = n; num1 >=1; num1--)
                               {
                                nFac = nFac * num1;
        }

                         out.print("\n Enter the value of r = ");

               Scanner in2 = new Scanner(System.in);
               int input2 = in2.nextInt();

                // saving a copy of input2 which is = r
                                             r = input2;


         // calculating the value of (n - r) as n_Sub_r
                                         n_Sub_r = (n - r);

                                   // calculating n - r factorial
                                         int n_rFac = 1;

         for(int num2 = n_Sub_r; num2 >=1; num2--)
         {
          n_rFac = n_rFac * num2;
         }

                                   // calculating r factorial
     int rFac = 1;

    for(int num3 = r; num3 >=1; num3--)
  {
   rFac = rFac * num3;
  }
                         // calculating (n!/(n-r)!r!)

                         int result = (nFac / (n_rFac * rFac));

                         out.printf("\n %dC%d = %d\n\n" , n ,r, result);
          }
          }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
How to use? Simple; copy and paste code in any IDE of your choice, save, compile then run. GOOD LUCK
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Thursday, January 23, 2014

An Application Package on Data Encryption and Decryption ~~ VisualBasic Code Snippet + GUI Design

In cryptography, a substitution cipher is a method of  encoding by which units of plaintext are replaced with ciphertext, according to a regular system; the "units" may be single letters (the most common), pairs of letters, triplets of letters, mixtures of the above, and so forth. The receiver deciphers the text by performing an inverse substitution.
There are a number of different types of substitution cipher. If the cipher operates on single letters, it is termed a simple substitution cipher; a cipher that operates on larger groups of letters is termed polygraphic. A monoalphabetic cipher uses fixed substitution over the entire message, whereas a polyalphabetic cipher uses a number of substitutions at different positions in the message, where a unit from the plaintext is mapped to one of several possibilities in the ciphertext and vice versa. http://en.wikipedia.org/wiki/Substitution_cipher

** Click here for 3DES (Data Encryption & Decryption)

Shown below is the screen shot and source code for each module respectively of a data encryption and decryption system using simple substitution cipher.

Screen shot for 'Start Page'
-----------------------------

















Source code for 'Start Page'
-----------------------------
Public Class Start_Page

    Private Sub encrypt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles encrypt.Click
        frmEncrypt.ShowDialog()
    End Sub

    Private Sub Start_Page_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        Me.Height = 357
        Me.Width = 634
    End Sub

    Private Sub decrypt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles decrypt.Click
        frmDecrypt.ShowDialog()
    End Sub

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


End Class


Screen shot for 'frmEncrypt'
-----------------------------
















Source code for 'frmEncrypt'
-----------------------------
Public Class frmEncrypt

    Private Sub cmdopen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdopen.Click
        ofd.ShowDialog()
        txtfilename.Text = ofd.FileName

        Try
            txtoriginal.Text = My.Computer.FileSystem.ReadAllText(ofd.FileName)
        Catch ex As Exception  ' Bad practice (catching exception)
            Dim a As String
            a = MessageBox.Show("File not found, Check the file name and try again", "Encryption", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            cmdopen.Focus()
            txtfilename.Text = String.Empty
        End Try
    End Sub

    Private Sub cmdsaveencrypt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdsaveencrypt.Click
        If txtEncrypted.Text = String.Empty Then
            Dim a As String
            a = MessageBox.Show("File not found; Check to make sure the file has been encrypted", "Encryption", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            cmdopen.Focus()
        Else

            Dim inn As String
            inn = InputBox("Enter file name")

            If inn = "" Then

            Else
                System.IO.File.WriteAllText("'" & inn & " ' ", txtEncrypted.Text)

                Dim haha As String
                haha = MessageBox.Show("File saved", "Encryption", MessageBoxButtons.OK, MessageBoxIcon.Information)
                txtEncrypted.Text = String.Empty
                txtoriginal.Text = String.Empty
                txtfilename.Text = ""

            End If
          End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdencrypt.Click
        Try
            txtEncrypted.Text = My.Computer.FileSystem.ReadAllText(ofd.FileName).ToLower.Replace("a", "/").Replace("b", "\").Replace("c", "*").Replace("d", "-").Replace("e", "+").Replace("f", "^").Replace("g", "<").Replace("h", ">").Replace("i", "!").Replace("j", "~").Replace("k", "@").Replace("l", "#").Replace("m", "$").Replace("n", "%").Replace("o", "&").Replace("p", "(").Replace("q", ")").Replace("r", "{").Replace("s", "}").Replace("t", "[").Replace("u", "]").Replace("v", "=").Replace("w", "'").Replace("x", "`").Replace("y", ";").Replace("z", ":").Replace("1", "|").Replace("2", "_")

            '-------substitution area--a.k.a replacement cipher------
       
        Catch ex As Exception
            Dim w As String
            w = MessageBox.Show("Check to make sure a file is selected", "Encryption", MessageBoxButtons.OK, MessageBoxIcon.Information)
            cmdopen.Focus()
        End Try
    End Sub
  
    Private Sub cmdclose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdclose.Click
        Me.Close()
    End Sub

    Private Sub frmEncrypt_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        Me.Height = 534
        Me.Width = 970
    End Sub

    Private Sub cmdclear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdclear.Click
        txtoriginal.Text = ""
        txtEncrypted.Text = ""
        txtfilename.Text = ""
        cmdopen.Focus()
    End Sub

    Private Sub frmEncrypt_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class

Screen shot for 'frmDecrypt'
-----------------------------

















Source code  for 'frmDecrypt'
-----------------------------
Public Class frmDecrypt

    Private Sub cmdopen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdopen.Click

        Try
            OpenFileDialog1.ShowDialog()
            txtfilename.Text = OpenFileDialog1.FileName
            txtoriginal.Text = My.Computer.FileSystem.ReadAllText(OpenFileDialog1.FileName)
        Catch ju As Exception
            Dim viva As String
            viva = MessageBox.Show("No file selected", "Decryption", MessageBoxButtons.OK, MessageBoxIcon.Information)
            cmdopen.Focus()
            txtfilename.Clear()

        End Try
    End Sub

    Private Sub cmddecrypt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmddecrypt.Click
        If txtoriginal.Text = "" Then
            Dim viv As String
            viv = MessageBox.Show("No file selected for decryption", "Decryption", MessageBoxButtons.OK, MessageBoxIcon.Information)

        Else
            txtdecrypted.Text = My.Computer.FileSystem.ReadAllText(OpenFileDialog1.FileName).ToLower.Replace("/", "a").Replace("\", "b").Replace("*", "c").Replace("-", "d").Replace("+", "e").Replace("^", "f").Replace("<", "g").Replace(">", "h").Replace("!", "i").Replace("~", "j").Replace("@", "k").Replace("#", "l").Replace("$", "m").Replace("%", "n").Replace("&", "o").Replace("(", "p").Replace(")", "q").Replace("{", "r").Replace("}", "s").Replace("[", "t").Replace("]", "u").Replace("=", "v").Replace("'", "w").Replace("`", "x").Replace(";", "y").Replace(":", "z").Replace("|", "1").Replace("_", "2")
            '--.....decryption arena....don't touch--------------------------------
        End If
    End Sub

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

    Private Sub frmDecrypt_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        Me.Height = 534
        Me.Width = 970
    End Sub

    Private Sub cmdsavedecrypt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdsavedecrypt.Click
        If txtdecrypted.Text = String.Empty Then
            Dim a As String
            a = MessageBox.Show("File not found", "Decryption", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            cmdopen.Focus()
        Else
            Dim oops As String
            oops = InputBox("Enter file name")

            If oops = "" Then
' Do nothing
            Else
                System.IO.File.WriteAllText("'" & oops & " ' ", txtdecrypted.Text)

                Dim ha As String
                ha = MessageBox.Show("File saved", "Decryption", MessageBoxButtons.OK, MessageBoxIcon.Information)
                txtdecrypted.Text = String.Empty
                txtoriginal.Text = String.Empty
                txtfilename.Text = ""
                'GoTo k
            End If
        End If
    End Sub

    Private Sub btnclear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnclear.Click
        txtoriginal.Text = ""
        txtdecrypted.Text = ""
        txtfilename.Text = ""
        cmdopen.Focus()
    End Sub
End Class
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Click here for Tripple DES (Data Encryption & Decryption)
============================================

Friday, January 17, 2014

An Application Package on Electronic Voting System (EVS) ~~ VisualBasic & SQL Server Code Snippet + GUI Design

First, i would like to say "Happy Newest year to you; yes! you". Haven't seen my new year gift yet? simply run the below java code AND boOOOomm! you would see/receive it.

import javax.swing.JOptionPane;     
class HappyNewYear
{
           String sMessage = "** Happy New Year!!!!!!!! **";

          HappyNewYear()
        {
          JOptionPane.showMessageDialog(null, sMessage);
         }
     public static void main(String [] args)
     {
            new HappyNewYear();
     }
}

Ok, back to business;
Electronic voting, also known as e-voting is a term encompassing several types of voting, embracing both electronic means of casting a vote and electronic means of counting votes ~> http://en.wikipedia.org/wiki/Electronic_voting ; Modules/Screen shots used in the design of  this system are as follows:

Login Screen: - Because this package is designed using Nigeria as a case study, Independent national electoral commission {inec} officials are expected to login into the system using their individual login details.



Finger Print Authentication Screen: - to cast your vote, voter(s) is/are expected to gain access into the main page {cast ballot Screen} using his/her right thumb print for authentication.


a.k.a Page 1 / 2, Next 3 screen shots are the Cast Ballot Screen(s): - shown, in the first screen shot, is the voting page a.k.a cast ballot screen with sample presidential/vice presidential candidates. From the screen view, you would notice that this package is a two party e-voting system. Sample parties used are the two current strongholds in Nigeria i.e. PDP and APC.


The below screen displays the presidential/Vice Presidential screen with APC as the voters choice while the next screen displays the presidential/Vice Presidential screen with PDP as the voters choice.




The same process is used for Governor/Deputy Governor Screen which is Page 2 / 2,



Microsoft Sql server is used as the database design for this system.