Thursday, February 3, 2011

Text to Speech in vb.net

















To Create Text to speech control in vb.net you have to first of all add a new reference.

1)How to add reference in vb project?
a. From Project menu -> add reference

Step 1:- Add Reference.
We Have to add a reference named with "microsoft speech object library" which located in
add reference -> COM -> microsoft speech object library
than press ok.

Step 2:- Taking controls on Form.
  • Take TrackBar , TextBox and Button controls on Form.
Step 3:- Write Coding.

Go to The Coding Window and Write Below Coding.

Imports SpeechLib    '(To Import a New Namespace Named SpeechLib.)
Public Class Form1

    Public WithEvents voice As New SpVoice
    Public Speed_Of_Speech As Integer = 1

    Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll
        Try
            Speed_Of_Speech = TrackBar1.Value
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            voice.Rate = Speed_Of_Speech
            voice.Speak(TextBox1.Text, SpeechVoiceSpeakFlags.SVSFDefault)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
End Class

Thursday, November 11, 2010

vb.net - drag_n_drop_with_magic_matrix



Public Class Form1

    Dim chk(8) As Integer

    Private Sub Button1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseDown, Button2.MouseDown, Button3.MouseDown, Button4.MouseDown, Button5.MouseDown, Button6.MouseDown, Button7.MouseDown, Button8.MouseDown, Button9.MouseDown, Button10.MouseDown
        sender.DoDragDrop(sender.Text, DragDropEffects.Copy)
    End Sub

    Private Sub Buttons_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Button11.DragDrop, Button12.DragDrop, Button13.DragDrop, Button14.DragDrop, Button15.DragDrop, Button16.DragDrop, Button17.DragDrop, Button18.DragDrop, Button19.DragDrop
        sender.text &= e.Data.GetData(DataFormats.Text).ToString
    End Sub

    Private Sub Buttons_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Button11.DragEnter, Button12.DragEnter, Button13.DragEnter, Button14.DragEnter, Button15.DragEnter, Button16.DragEnter, Button17.DragEnter, Button18.DragEnter, Button19.DragEnter
        e.Effect = DragDropEffects.Copy
    End Sub

    Private Sub Button12_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button11.MouseDown, Button12.MouseDown, Button13.MouseDown, Button14.MouseDown, Button15.MouseDown, Button16.MouseDown, Button17.MouseDown, Button18.MouseDown, Button19.MouseDown
        sender.DoDragDrop(sender.Text, DragDropEffects.Copy)
        If Val(sender.text) <> 0 Then
            sender.text = Val(sender.text \ 10)
            If Val(sender.text) = 0 Then
                sender.text = ""
            End If
        End If
    End Sub

    Private Sub Button20_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Button20.DragDrop, Button21.DragDrop
        sender.text = e.Data.GetData(DataFormats.Text).ToString
    End Sub

    Private Sub Button20_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Button20.DragEnter, Button21.DragEnter
        e.Effect = DragDropEffects.Copy
    End Sub

    Private Sub Button21_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button21.Click
        Dim i, j As Integer
        Dim myctrl As Control
        i = 0
        For Each myctrl In Panel1.Controls
            chk(i) = Val(myctrl.Text)
            i += 1
        Next
        For i = 0 To 8
            For j = i + 1 To 8
                If chk(i) = chk(j) Then
                    MessageBox.Show("value enter is repeted !!!" & vbNewLine & "plese check all the numbers......", "check the values", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
                    Exit Sub
                End If
            Next
        Next
        chk1()
    End Sub

    Private Sub Button22_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button22.Click
        Dim myctrl As Control
        For Each myctrl In Panel1.Controls
            myctrl.Text = ""
        Next
    End Sub

    Sub chk1()
        If Val(Val(Button11.Text) + Val(Button12.Text) + Val(Button13.Text)) = 15 Then
            If Val(Val(Button14.Text) + Val(Button15.Text) + Val(Button16.Text)) = 15 Then
                If Val(Val(Button17.Text) + Val(Button18.Text) + Val(Button19.Text)) = 15 Then
                    If Val(Val(Button11.Text) + Val(Button15.Text) + Val(Button19.Text)) = 15 Then
                        If Val(Val(Button11.Text) + Val(Button14.Text) + Val(Button17.Text)) = 15 Then
                            If Val(Val(Button12.Text) + Val(Button15.Text) + Val(Button18.Text)) = 15 Then
                                If Val(Val(Button13.Text) + Val(Button16.Text) + Val(Button19.Text)) = 15 Then
                                    If Val(Val(Button13.Text) + Val(Button15.Text) + Val(Button17.Text)) = 15 Then
                                        MessageBox.Show("matrix is magic matrik", "testing", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
                                        Exit Sub
                                    Else
                                        MessageBox.Show("matrix is not magic matrik", "testing", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
                                        Exit Sub
                                    End If
                                End If
                            End If
                        End If
                    End If
                End If
            End If
        End If
    End Sub


    Private Sub Button23_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button23.Click
        Dim frm As Form2
        frm = New Form2
        frm.Show()
    End Sub

End Class