Wednesday, January 19, 2011

ProgressBar with Voice








'Make sure for this one you already installed a Microsoft Text To Speach Lib/DSK on your Computer
If not then download from :




Imports SpeechLib
Public Class Form1
    Dim voice As SpeechLib.ISpeechVoice
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer1.Interval = 1000
        Timer1.Enabled = True
        voice = New SpeechLib.SpVoice
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        ProgressBar1.Value = ProgressBar1.Value + 1
        Label1.Text = ProgressBar1.Value & " % Complete"
        If ProgressBar1.Value = 25 Then
            voice.Speak(ProgressBar1.Value & " % complete")
        End If
        If ProgressBar1.Value = 50 Then
            voice.Speak(ProgressBar1.Value & " % complete")
        End If
        If ProgressBar1.Value = 75 Then
            voice.Speak(ProgressBar1.Value & " % complete")
        End If
        If ProgressBar1.Value = 100 Then
            voice.Speak(ProgressBar1.Value & " % loading complete")
        End If
        If ProgressBar1.Value = 100 Then
            Timer1.Enabled = False
        End If
    End Sub
End Class

Video Recording in AVI format using HyCam SDK

For this tutorial you need to install HyCam SDK on your computer then add reference which is shown below in screen shot with red square marking.


Following screen shows the design mode of form
Imports HyCam2
Public Class Form1
    Dim cam1 As New HyCam2.HyCam2
    Dim sfd As New SaveFileDialog
    Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
        sfd.Filter = "AVI Files (*.avi)|*.avi|All Files(*.*)|*.*"
        sfd.FileName = "Save.avi"
        sfd.DefaultExt = "*.avi"
        sfd.ShowDialog()
        cam1.FileName = sfd.FileName.ToString
        cam1.RecordCursor = True
        cam1.RecordSound = True
        cam1.StartX = My.Computer.Screen.Bounds.X
        cam1.StartY = My.Computer.Screen.Bounds.Y
        cam1.Height = My.Computer.Screen.Bounds.Height
        cam1.Width = My.Computer.Screen.Bounds.Width
        cam1.StartRec()
    End Sub

    Private Sub BtnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnStop.Click
        cam1.StopRec()
    End Sub

    Private Sub camOn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles camOn.Click
        AxWindowsMediaPlayer1.Visible = True
        Dim str As String
        str = sfd.FileName
        AxWindowsMediaPlayer1.launchURL(str)
    End Sub

    Private Sub camOff_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles camOff.Click
        AxWindowsMediaPlayer1.Visible = False
    End Sub
End Class


How to check file is Tempering or not with existing file


We can see if the file is tempering or not using Cryptography

Code:


Imports System.IO
Imports System.Security.Cryptography
Public Class Form1
   
    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Application.Exit()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        OpenFileDialog1.Title = "Open File"
        OpenFileDialog1.Filter = "Files (*.*)|*.*"
        If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.Cancel Then
            Exit Sub
        End If
        Dim sFilePath As String = OpenFileDialog1.FileName
        If System.IO.File.Exists(sFilePath) = False Then
            sFilePath = ""
            Exit Sub
        Else
            TextBox1.Text = sFilePath
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        OpenFileDialog1.Title = "Open File"
        OpenFileDialog1.Filter = "Files (*.*)|*.*"
        If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.Cancel Then
            Exit Sub
        End If
        Dim sFilePath As String = OpenFileDialog1.FileName
        If System.IO.File.Exists(sFilePath) = False Then
            sFilePath = ""
            Exit Sub
        Else
            TextBox2.Text = sFilePath
        End If
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Dim myHash As HashAlgorithm
        myHash = HashAlgorithm.Create()
        If TextBox2.Text = String.Empty Or Me.TextBox1.Text = String.Empty Then
            MessageBox.Show("Set all form fields prior to initiating a test", _
            "Missing Form Data", MessageBoxButtons.OK)
        End If
        Dim fs1 As New FileStream(TextBox2.Text, FileMode.OpenOrCreate)
        Dim fs1Bytes As Byte() = New Byte(fs1.Length) {}
        fs1.Read(fs1Bytes, 0, fs1.Length)
        Dim arr1() As Byte = myHash.ComputeHash(fs1Bytes)
        fs1.Close()
        Dim fs2 As New FileStream(TextBox1.Text, FileMode.OpenOrCreate)
        Dim fs2Bytes As Byte() = New Byte(fs2.Length) {}
        fs2.Read(fs2Bytes, 0, fs2.Length)
        Dim arr2() As Byte = myHash.ComputeHash(fs2Bytes)
        fs2.Close()
        If BitConverter.ToString(arr1) = BitConverter.ToString(arr2) Then
            MessageBox.Show("The file examined has not been tampered with.", "Hash" & _
            "Test Passed")
            'display comparison
            MessageBox.Show("Original Hash: " & Environment.NewLine &
            BitConverter.ToString(arr1) & _
            Environment.NewLine & _
            "Test Hash: " & Environment.NewLine & _
            BitConverter.ToString(arr2), "Hash Test Results")
        Else
            MessageBox.Show("The file examined has been tampered with.", "Hash Test Failed")
            'display comparison
            MessageBox.Show("Original Hash: " & Environment.NewLine &
            BitConverter.ToString(arr1) & _
            Environment.NewLine & _
            "Test Hash: " & Environment.NewLine & _
            BitConverter.ToString(arr2), "Hash Test Results")
        End If
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        'Dim myhash As Byte
        'Dim fs1 As New FileStream(TextBox2.Text, FileMode.OpenOrCreate)
        'Dim fs1Bytes As Byte() = New Byte(fs1.Length) {}
        'fs1.Read(fs1Bytes, 0, fs1.Length)
        'Dim arr1() As Byte = myhash.CompareTo(fs1Bytes)
        'fs1.Close()
        Dim fs1 As New FileStream(TextBox2.Text, FileMode.OpenOrCreate)
        Dim fs1Bytes As Byte() = New Byte(fs1.Length) {}
        fs1.Read(fs1Bytes, 0, fs1.Length)
        fs1.Close()
        Dim fs2 As New FileStream(TextBox1.Text, FileMode.OpenOrCreate)
        Dim fs2Bytes As Byte() = New Byte(fs2.Length) {}
        fs2.Read(fs2Bytes, 0, fs2.Length)
        fs2.Close()
        Dim i As Integer = 0
        For i = 0 To fs1Bytes.Length - 1
            If Not fs1Bytes(i) = fs2Bytes(i) Then
                MessageBox.Show("The file examined has been tampered with at position " & _
                i.ToString(), "Byte Test Failed")
                Exit Sub
            End If
        Next
        MessageBox.Show("The file examined has not been tampered with.", "Byte Test Passed")
    End Sub

End Class