Sunday 22 September 2013

string to double in vb.net

DEMO PROJECT TO CONVERT STRING VALUE TO DOUBLE USING VB2010


To convert a string  to double in .net there are many methods available . A string value is collection of number of characters within a string variable eg:-

Dim a as string = " A String Value "

Double values are  floating point numbers . These are values with precession To convert a string value to double value the main avaliable methods are :-

* CDBL Method    :-                 Cdbl ( string_value ) 

* Convert . ToDouble   :-          Convert . ToDouble ( string_value )  

* TryParse Method 

The Best Method to convert string value to double from methods given above is TryParse . TryParse will first check whether given string value can be converted to double or not If these values cannot be converted into Double then it does not return anything . TryParse method is used with if condition to check whether string value can be converted to double or not If it cannot be converted to Double value then we can Pass string in message box that "This Value Cannot Be Converted To  Double"

Design of Project string to double in vb.net



Code for string to double in vb.net


Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim string_value As String
        string_value = TextBox1. Text
        Dim double_value As Double
        If Double.TryParse(string_value, double_value) Then
            MsgBox(double_value)
        Else
MsgBox("This String Value Cannot Be Converted To Double")
        End If
    End Sub

End Class

Explanation of Code :- string to double in vb.net



  1. Public class Form1
    In first line, i have declared a class . The access specifier of class is Public so that in case of using inheritance other class can easily access this class by using an instance or object of this class
  2.  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  3. Here, We have declared a Private Sub Procedure name Button1. This sub-procedure is of object Named or control named Button1 . 
  • Button1_Click , Here we are declaring an Event for Button Control. We are using click event so that the procedure will execute or code that is written under this Button1 control will run when click the button at runtime.
  • Dim String_value as string , In this line of code we have simply declared a variable named "string_value" . Dim is a keyword that is used in visual basic to declare a variable . followed by name of variable by keeping in mind the rules for declaring the variable in visual baisc. Then 'as ' is also a keyword this keyword is used to specify followed by it that what type of data we are going to store in the variable that we are creating now. Then we will provide the datatype of variable

     4. " string_value = TextBox1. Text" :- Now we are simply assigning the value that we enter in the textbox at runtime into string variable we have created in previous step

    5.  Dim double_value As Double , In this line of code we have simply declared a variable named "double_value" . Dim is a keyword that is used in visual basic to declare a variable . followed by name of variable by keeping in mind the rules for declaring the variable in visual baisc. Then 'as ' is also a keyword this keyword is used to specify followed by it that what type of data we are going to store in the variable that we are creating now. Then we will provide the datatype of variable

    6. In code below we have used Try.Parse this is mainly used to try that the value given as parameter of type string can be converted into double value or not . If this value cannot be converted from string to double in .net then it will execute the else statement telling the Trying to Parse string value into double value is unsuccessfull . If given value can be converted then it will convert it and given the message along with string to double converted value
     If Double.TryParse(string_value, double_value) Then
                MsgBox(double_value)
            Else
    MsgBox("This String Value Cannot Be Converted To Double")
            End If

    7. Then End Sub will close the Button1_click subprocedure  and End Class will end the class form1

Tuesday 10 September 2013

delete record from access database

To delete Record from Access database we have used Dataset and Oledbdataadapters 

DataAdapter :- DataAdapter  is like a pipeline or path or bridge that is used to execute the given query on database table . DataAdapter that we have used is OledbdataAdapter as we are using MS-Access as database . Data Adapter first takes the command to be executed on table data from Oledbcommand object and this object contains the query that is to be executed on database . Then it execute query on Database table data and store resultant data in form of rows and columns or Tabulated form in Dataset

Dataset :- Dataset is generally a memory area where the result of the query that we have executed on database is placed . When a query is passed by using Oledbdataadapter to execute that query on database specified table . Then the result of the query has to be placed some to use it . Like to show it in Datagridview or to show that result data in Textboxes or to manupulate the data and then save that manipulated data again to Table in database

DOWNLOAD this Demo Project from my gmail upload link :-

Steps to Make Microsoft Access Database:

1. Go to desired location you want to make your Database
2. Right click then click on new and 
3. Then click Microsoft Access 2007 Database
4. Create Desired Table with required Fields 
5. Save it as Microsoft Access database 2003 format 
6. click ok 

DOWNLOAD THIS Demo Database from my gmail upload link :-


Steps To Make This Demo Project :-


1. Start your Visual Studio 2010 
2. At start page click on Create New Project 
3. In Dialog Box provide Project name and path where to save this project and click ok
4. Now from Toolbox Drag one ComboBox , one Label and One Button
5. Now Change Label 'Text' Property to "ID_num"
6. Now Change Button 'Text' Property to "Delete"
7. Make Design as shown below

Design of Form 1 


8.  In Below image you can see there are two records in Data base Table 'info_table ' .


9. Now Run the Application 
10. Click on Down arrow of combobox Your ID-num will be shown as image below



11. Now select an id_num from combobox items and then click on Delete


12. Now Record will be deleted from database table as shown below



Code for Application 


Imports System.Data.OleDb


'http://www.geeksprogrammings.blogspot.in

Public Class Form1
    Dim connection As New OleDbConnection
    Dim Del_command As New OleDbCommand
    Dim select_command As New OleDbCommand
    Dim ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
        "C:\test.mdb"
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        connection.ConnectionString = ConnectionString
        connection.Open()
        select_command.CommandText = "select id_num from info_table"
        select_command.CommandType = CommandType.Text
        Dim adapter As New OleDbDataAdapter("select id_num from info_table", connection)
        'adapter.SelectCommand = select_command
        Dim dt As New DataTable
        adapter.Fill(dt)
        select_command.Connection = connection
        select_command.ExecuteNonQuery()
        Dim i As New Integer
        For i = 0 To dt.Rows.Count - 1
            ComboBox1.Items.Add(dt.Rows(i).Item(0))
        Next
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Del_command.CommandText = "delete from info_table where id_num=@id_num"
        Del_command.Parameters.AddWithValue("@id_num", ComboBox1.SelectedItem)
        Del_command.CommandType = CommandType.Text
        Del_command.Connection = connection
        Del_command.ExecuteNonQuery()
        MsgBox("Record Deleted ")
    End Sub


Explanation of Code


Imports System.Data.OleDb


This line of code tells we are importing Oledb Namespace. Oledb stands for Object Linking and Embedding . For using Access database with .net applications we have to inherit classes from this oledb Namespace . Oledb Namespace contains all classes that are required to connect vb.net/c# application to Microsoft Access
Database




Public Class Form1
    Dim connection As New OleDbConnection
    Dim command As New OleDbCommand
    Dim ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & "C:\test.mdb
End Class

Now In These lines of code we declared 3 things
1. OledbConnection :- OledbConnection is a class contained in System.Data.Oledb Namespace and it is used to make connectivity to Access Database . It receives the connection string that tells the path of Microsoft Access Database to connect to it. In this line of code we have created instance of Oledbconnection class

2. OledbCommand :- OledbCommand is a class contained in S
ystem.Data.Oledb Namespace and it is used to define or specify the command that we are going to execute on Microsoft Access Database. In this line of code we are creating instance of OledbCommand to use this instance in further code

3. Connection string :- Now we are creating a variable named connectionString that will receive the string or path that tell how we connect to our Access database. It receives two parameters :-
Provider=Microsoft.Jet.OLEDB.4.0 -- 
Data Source=" & "C:\test.mdb

Now Provider is main part here in connection string . Provider is different for different approaches used for connecting data to database . The Connection string contains information that the Provider needs to know to connect to database Once connected then rest of job is done by provider


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

        connection.ConnectionString = ConnectionString
        connection.Open()
    End Sub

Now in this block of code we have initialized our OledbConnection instance with connection string variable that we have initialized in previous step. So in this code we have given the Oledbconnectin instance means connection some information about Provider to use and location of database file on computer

Then we have used connection.open() method opens port for Enter into Access Database. this opens a pipe to execute query in database

How To Use Access database with vb.net

Sunday 8 September 2013

Saturday 7 September 2013

Access database with vb.net


Microsoft Access database is a Database Management System developed By Microsoft and it is very simple and easy to use for windows application and web application development with Dotnet . Platform. . It supports Microsoft Jet Database Engine . It supports Graphical User Interface with Professional Development tools.

Microsoft is well supported database to be used in Microsoft Visual Studio to develop applications. It is very easy to connect .net either vb.net or C#.net application with Microsoft Access Database

DOWNLOAD this Demo Project from my gmail upload link :-


Steps to Make Microsoft Access Database:

1. Go to desired location you want to make your Database
2. Right click then click on new and 
3. Then click Microsoft Access 2007 Database
4. Create Desired Table with required Fields 
5. Save it as Microsoft Access database 2003 format 
6. click ok 

DOWNLOAD THIS Demo Database from my gmail upload link :-

Steps To Make This Demo Project :-


1. Start your Visual Studio 2010 
2. At start page click on Create New Project 
3. In Dialog Box provide Project name and path where to save this project and click ok
4. Now from Toolbox Drag four Textboxes 
5. Drag 1 Button and make design as show in below image

Design of Form 1 



6. Now copy the code given in code section below :-


Code of Form1



Imports System.Data.OleDb

Public Class Form1

    Dim connection As New OleDbConnection
    Dim command As New OleDbCommand
    Dim ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & "C:\test.mdb"

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        command.CommandText = "insert into info_table values (" & TextBox1.Text & ",'" & TextBox2.Text & "','" & TextBox3.Text & "'," & TextBox4.Text & ")"
        command.CommandType = CommandType.Text
        command.Connection = connection
        command.ExecuteNonQuery()
        MsgBox("Record inserted ")
    End Sub

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

        connection.ConnectionString = ConnectionString
        connection.Open()
    End Sub

End Class


Explanation of Code


Imports System.Data.OleDb


This line of code tells we are importing Oledb Namespace. Oledb stands for Object Linking and Embedding . For using Access database with .net applications we have to inherit classes from this oledb Namespace . Oledb Namespace contains all classes that are required to connect vb.net/c# application to Microsoft Access
Database




Public Class Form1
    Dim connection As New OleDbConnection
    Dim command As New OleDbCommand
    Dim ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & "C:\test.mdb
End Class


Now In These lines of code we declared 3 things
1. OledbConnection :- OledbConnection is a class contained in System.Data.Oledb Namespace and it is used to make connectivity to Access Database . It receives the connection string that tells the path of Microsoft Access Database to connect to it. In this line of code we have created instance of Oledbconnection class

2. OledbCommand :- OledbCommand is a class contained in S
ystem.Data.Oledb Namespace and it is used to define or specify the command that we are going to execute on Microsoft Access Database. In this line of code we are creating instance of OledbCommand to use this instance in further code

3. Connection string :- Now we are creating a variable named connectionString that will receive the string or path that tell how we connect to our Access database. It receives two parameters :-

Provider=Microsoft.Jet.OLEDB.4.0 -- 
Data Source=" & "C:\test.mdb

Now Provider is main part here in connection string . Provider is different for different approaches used for connecting data to database . The Connection string contains information that the Provider needs to know to connect to database Once connected then rest of job is done by provider


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

        connection.ConnectionString = ConnectionString
        connection.Open()
    End Sub

Now in this block of code we have initialized our OledbConnection instance with connection string variable that we have initialized in previous step. So in this code we have given the Oledbconnectin instance means connection some information about Provider to use and location of database file on computer

Then we have used connection.open() method opens port for Enter into Access Database. this opens a pipe to execute query in database 

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        command.CommandText = "insert into info_table values (" & TextBox1.Text & ",'" & TextBox2.Text & "','" & TextBox3.Text & "'," & TextBox4.Text & ")"
        command.CommandType = CommandType.Text
        command.Connection = connection
        command.ExecuteNonQuery()
        MsgBox("Record inserted ")
    End Sub

Now at last we have used insert query that is coded on Button Click Event . In this code I have told which commandtext to choose and what will be commandType test or storeprocedure . and also we have initialized the command with Oledbconnection instance. Then we have execute command using ExecuteNonQuery() method. This method returns the number of rows affected the database

Delete Record from Access Database

Wednesday 4 September 2013

Text-To-Speech .NET

This post is to introduce you with SAPI that allows a user to make an automated system that will send the input given by user to speakers and then Speakers will speak or output that text

* SAPI Stands for Speech Application Programming Interface . It is an API developed by Microsoft
to allow users to develop speech recognition systems. 

* The first version of SAPI was released in 1995. This is a program that offers Text-To-Speech and speech Recognition Capabilities. 

* SAPI interfaces are provided for C,C++,C# and visual Basic Languages. 

* SAPI is most widely used application program interface ( API ) used today

CODE For Text - To - Speech in  VB.NET 


Dim SAPI
SAPI = CreateObject ( "sapi.spvoice" ) 
SAPI.speak( TextBox2.Text )

In order to Use SAPI we have to create object of SAPI . In Code Above in line 2 we have created object assigned it SAPI . SAPI is a simple variable nothing more than that there is no need to be confused about that . Then we have used speak ( )  method to give or direct the input to speakers to speak or output all given input.


DEMO APPLICATION FOR SAPI

DEMO APPLICATION 1


DOWNLOAD DEMO APPLICATION FROM LINK BELOW


CODE  FOR DEMO APPLICATION :- 


Public Class Form1

    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress

        Dim i As Integer
        i = 0
        Dim ch As Char
        ch = e.KeyChar

        If ch = " " Then
            Dim SAPI
            SAPI = CreateObject("sapi.spvoice")
            SAPI.speak(TextBox2.Text)
            TextBox2.Text = ""

        Else
TextBox2.text = TextBox2.text + ch;
        End If

    End Sub

Explanation Of Code

In this code I have taken a variable i of type integer and initialized it to Zero . I have taken a  char type variable that will take character typed or cached by keypress event. 

First in If ( ) codition  i have checked whether the entered character is a blank space or not .If entered character is not a blank space then this code just add the entered character to the TextBox and If user has pressed a space then the complete word will be spoken by SAPI object .

This code spoke the words not only characters entered by user it first takes the characters and then collect them and after completion of word it passes it to SAPI object and SAPI will give that word as output to speaker to spoke it

DEMO APPLICATION 2


DOWNLOAD DEMO APPLICATION 2 FROM LINK BELOW




DEMO APPLICATION 3


DOWNLOAD DEMO APPLICATION 3 FROM LINK BELOW
https://docs.google.com/file/d/0ByR2IblIaEGyOGpuT0NiaTZIZHM/edit



Sunday 1 September 2013

Make calculator in .net

There are number of calculators available . If you want to make a Basic calculator in .NET Then you can surf a number of Calculators code on the Internet . But If you have used the calculators come in Microsoft-Windows PC's Then you can notice these are best , easy to operate and can accept no of operators one time as these are advanced calculators . So make a calculator similar to these calculators come in Microsoft-Windows PC's is logical way of developing a calculator. I have tried a simple calculator That only does Addition , Substration, Division and Multiplication of integers and Fractional numbers .