Click here to Skip to main content
Click here to Skip to main content
Articles » Web Development » ASP.NET » Samples » Downloads
 
Add your own
alternative version

Dictionary for Google Suggest like Dictionary

, 5 Jun 2005
To make a dictionary that will work with Google Suggest like Dictionary.
DictMaker_demo.zip
DictMaker_demo
DictMaker.exe
dict.mdb
DictMaker_src.zip
DictMaker
bin
DictMaker.vbproj.user
dict.mdb
Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents OFD As System.Windows.Forms.OpenFileDialog
    Friend WithEvents progbar2 As System.Windows.Forms.ProgressBar
    Friend WithEvents txtpath2 As System.Windows.Forms.TextBox
    Friend WithEvents btnopen2 As System.Windows.Forms.Button
    Friend WithEvents Button2 As System.Windows.Forms.Button
    Friend WithEvents txtpathtarget As System.Windows.Forms.TextBox
    Friend WithEvents Button3 As System.Windows.Forms.Button
    Friend WithEvents SFD As System.Windows.Forms.SaveFileDialog
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents TabControl1 As System.Windows.Forms.TabControl
    Friend WithEvents TabPage1 As System.Windows.Forms.TabPage
    Friend WithEvents TabPage2 As System.Windows.Forms.TabPage
    Friend WithEvents lblprocessed As System.Windows.Forms.Label
    Friend WithEvents lblTotalLines As System.Windows.Forms.Label
    Friend WithEvents ProgBar As System.Windows.Forms.ProgressBar
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents txtpath As System.Windows.Forms.TextBox
    Friend WithEvents btnOpen As System.Windows.Forms.Button
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents Label6 As System.Windows.Forms.Label
    Friend WithEvents Button4 As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.OFD = New System.Windows.Forms.OpenFileDialog
        Me.progbar2 = New System.Windows.Forms.ProgressBar
        Me.txtpath2 = New System.Windows.Forms.TextBox
        Me.btnopen2 = New System.Windows.Forms.Button
        Me.Button2 = New System.Windows.Forms.Button
        Me.txtpathtarget = New System.Windows.Forms.TextBox
        Me.Button3 = New System.Windows.Forms.Button
        Me.SFD = New System.Windows.Forms.SaveFileDialog
        Me.Label1 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.TabControl1 = New System.Windows.Forms.TabControl
        Me.TabPage1 = New System.Windows.Forms.TabPage
        Me.Label3 = New System.Windows.Forms.Label
        Me.TabPage2 = New System.Windows.Forms.TabPage
        Me.Label6 = New System.Windows.Forms.Label
        Me.Label4 = New System.Windows.Forms.Label
        Me.Label5 = New System.Windows.Forms.Label
        Me.lblprocessed = New System.Windows.Forms.Label
        Me.lblTotalLines = New System.Windows.Forms.Label
        Me.ProgBar = New System.Windows.Forms.ProgressBar
        Me.Button1 = New System.Windows.Forms.Button
        Me.txtpath = New System.Windows.Forms.TextBox
        Me.btnOpen = New System.Windows.Forms.Button
        Me.Button4 = New System.Windows.Forms.Button
        Me.TabControl1.SuspendLayout()
        Me.TabPage1.SuspendLayout()
        Me.TabPage2.SuspendLayout()
        Me.SuspendLayout()
        '
        'progbar2
        '
        Me.progbar2.Location = New System.Drawing.Point(64, 136)
        Me.progbar2.Maximum = 8
        Me.progbar2.Name = "progbar2"
        Me.progbar2.Size = New System.Drawing.Size(280, 16)
        Me.progbar2.TabIndex = 9
        '
        'txtpath2
        '
        Me.txtpath2.Location = New System.Drawing.Point(64, 72)
        Me.txtpath2.Name = "txtpath2"
        Me.txtpath2.Size = New System.Drawing.Size(280, 20)
        Me.txtpath2.TabIndex = 8
        Me.txtpath2.Text = ""
        '
        'btnopen2
        '
        Me.btnopen2.Location = New System.Drawing.Point(344, 72)
        Me.btnopen2.Name = "btnopen2"
        Me.btnopen2.Size = New System.Drawing.Size(24, 24)
        Me.btnopen2.TabIndex = 7
        Me.btnopen2.Text = "..."
        '
        'Button2
        '
        Me.Button2.Enabled = False
        Me.Button2.Location = New System.Drawing.Point(232, 168)
        Me.Button2.Name = "Button2"
        Me.Button2.Size = New System.Drawing.Size(232, 23)
        Me.Button2.TabIndex = 10
        Me.Button2.Text = "Make substrate (convert to delimted values)"
        '
        'txtpathtarget
        '
        Me.txtpathtarget.Location = New System.Drawing.Point(64, 104)
        Me.txtpathtarget.Name = "txtpathtarget"
        Me.txtpathtarget.Size = New System.Drawing.Size(280, 20)
        Me.txtpathtarget.TabIndex = 11
        Me.txtpathtarget.Text = ""
        '
        'Button3
        '
        Me.Button3.Location = New System.Drawing.Point(344, 104)
        Me.Button3.Name = "Button3"
        Me.Button3.Size = New System.Drawing.Size(24, 24)
        Me.Button3.TabIndex = 12
        Me.Button3.Text = "..."
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(16, 72)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(32, 16)
        Me.Label1.TabIndex = 13
        Me.Label1.Text = "Open"
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(16, 104)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(48, 16)
        Me.Label2.TabIndex = 14
        Me.Label2.Text = "Save as"
        '
        'TabControl1
        '
        Me.TabControl1.Controls.Add(Me.TabPage1)
        Me.TabControl1.Controls.Add(Me.TabPage2)
        Me.TabControl1.Location = New System.Drawing.Point(32, 24)
        Me.TabControl1.Name = "TabControl1"
        Me.TabControl1.SelectedIndex = 0
        Me.TabControl1.Size = New System.Drawing.Size(488, 224)
        Me.TabControl1.TabIndex = 15
        '
        'TabPage1
        '
        Me.TabPage1.Controls.Add(Me.Label3)
        Me.TabPage1.Controls.Add(Me.Label1)
        Me.TabPage1.Controls.Add(Me.progbar2)
        Me.TabPage1.Controls.Add(Me.txtpath2)
        Me.TabPage1.Controls.Add(Me.btnopen2)
        Me.TabPage1.Controls.Add(Me.Button2)
        Me.TabPage1.Controls.Add(Me.Button3)
        Me.TabPage1.Controls.Add(Me.txtpathtarget)
        Me.TabPage1.Controls.Add(Me.Label2)
        Me.TabPage1.Location = New System.Drawing.Point(4, 22)
        Me.TabPage1.Name = "TabPage1"
        Me.TabPage1.Size = New System.Drawing.Size(480, 198)
        Me.TabPage1.TabIndex = 0
        Me.TabPage1.Text = "Substrate"
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(24, 24)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(336, 24)
        Me.Label3.TabIndex = 15
        Me.Label3.Text = "Select to convert the HTML dictionary file into Delimted values"
        '
        'TabPage2
        '
        Me.TabPage2.Controls.Add(Me.Label6)
        Me.TabPage2.Controls.Add(Me.Label4)
        Me.TabPage2.Controls.Add(Me.Label5)
        Me.TabPage2.Controls.Add(Me.lblprocessed)
        Me.TabPage2.Controls.Add(Me.lblTotalLines)
        Me.TabPage2.Controls.Add(Me.ProgBar)
        Me.TabPage2.Controls.Add(Me.Button1)
        Me.TabPage2.Controls.Add(Me.txtpath)
        Me.TabPage2.Controls.Add(Me.btnOpen)
        Me.TabPage2.Location = New System.Drawing.Point(4, 22)
        Me.TabPage2.Name = "TabPage2"
        Me.TabPage2.Size = New System.Drawing.Size(480, 198)
        Me.TabPage2.TabIndex = 1
        Me.TabPage2.Text = "Enzyme"
        '
        'Label6
        '
        Me.Label6.Location = New System.Drawing.Point(24, 16)
        Me.Label6.Name = "Label6"
        Me.Label6.Size = New System.Drawing.Size(336, 24)
        Me.Label6.TabIndex = 17
        Me.Label6.Text = "Select the substrate(file delimted values) to saved in database"
        '
        'Label4
        '
        Me.Label4.Location = New System.Drawing.Point(16, 72)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(32, 16)
        Me.Label4.TabIndex = 15
        Me.Label4.Text = "Open"
        '
        'Label5
        '
        Me.Label5.Location = New System.Drawing.Point(16, 104)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(48, 16)
        Me.Label5.TabIndex = 16
        Me.Label5.Text = "Save as"
        '
        'lblprocessed
        '
        Me.lblprocessed.Location = New System.Drawing.Point(56, 168)
        Me.lblprocessed.Name = "lblprocessed"
        Me.lblprocessed.Size = New System.Drawing.Size(144, 23)
        Me.lblprocessed.TabIndex = 12
        Me.lblprocessed.Text = "Line(s) processed"
        '
        'lblTotalLines
        '
        Me.lblTotalLines.Location = New System.Drawing.Point(56, 144)
        Me.lblTotalLines.Name = "lblTotalLines"
        Me.lblTotalLines.Size = New System.Drawing.Size(144, 23)
        Me.lblTotalLines.TabIndex = 11
        Me.lblTotalLines.Text = "Total Line(s)"
        '
        'ProgBar
        '
        Me.ProgBar.Location = New System.Drawing.Point(72, 104)
        Me.ProgBar.Name = "ProgBar"
        Me.ProgBar.Size = New System.Drawing.Size(280, 16)
        Me.ProgBar.TabIndex = 10
        '
        'Button1
        '
        Me.Button1.Enabled = False
        Me.Button1.Location = New System.Drawing.Point(264, 160)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(200, 24)
        Me.Button1.TabIndex = 9
        Me.Button1.Text = "Bind to enzyme (save to database)"
        '
        'txtpath
        '
        Me.txtpath.Location = New System.Drawing.Point(72, 72)
        Me.txtpath.Name = "txtpath"
        Me.txtpath.Size = New System.Drawing.Size(280, 20)
        Me.txtpath.TabIndex = 8
        Me.txtpath.Text = ""
        '
        'btnOpen
        '
        Me.btnOpen.Location = New System.Drawing.Point(360, 72)
        Me.btnOpen.Name = "btnOpen"
        Me.btnOpen.Size = New System.Drawing.Size(24, 24)
        Me.btnOpen.TabIndex = 7
        Me.btnOpen.Text = "..."
        '
        'Button4
        '
        Me.Button4.Location = New System.Drawing.Point(472, 264)
        Me.Button4.Name = "Button4"
        Me.Button4.TabIndex = 16
        Me.Button4.Text = "Exit"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(560, 293)
        Me.Controls.Add(Me.Button4)
        Me.Controls.Add(Me.TabControl1)
        Me.Name = "Form1"
        Me.Text = "Dict Maker"
        Me.TabControl1.ResumeLayout(False)
        Me.TabPage1.ResumeLayout(False)
        Me.TabPage2.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

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

    End Sub

    
    Function CalculateEstimate(ByVal path As String) As Integer
        Dim estimate As New IO.StreamReader(path)
        Dim NumOfLines As Integer
        While estimate.Peek > -1
            estimate.ReadLine()
            NumOfLines += 1
        End While
        estimate.Close()
        lblTotalLines.Text = "Total Line(s): " & NumOfLines - 11
        Return NumOfLines
    End Function
    


    Private Sub btnopen2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnopen2.Click
        OFD.FileName = ""
        If OFD.ShowDialog = DialogResult.OK Then
            txtpath2.Text = OFD.FileName

        End If
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        SFD.FileName = ""
        If SFD.ShowDialog = DialogResult.OK Then
            txtpathtarget.Text = SFD.FileName

        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        progbar2.Value = 0
        Dim myfile = New IO.StreamReader(txtpath2.Text)
        Try

            '---Proceesing the file that contain delimted contents
            Dim Line As String
            Line = myfile.Readtoend

            '----Remove unwanted tags
            Line = Line.Replace("<P>", "")
            progbar2.Value += 1

            Line = Line.Replace("</P>", "")
            progbar2.Value += 1

            Line = Line.Replace("<B>", "")
            progbar2.Value += 1

            Line = Line.Replace(" (<I></I>) ", "@")
            progbar2.Value += 1

            Line = Line.Replace("</B>", "@")
            progbar2.Value += 1

            Line = Line.Replace(" (<I>", "")
            progbar2.Value += 1

            Line = Line.Replace("</I>) ", "@")
            progbar2.Value += 1

            Dim myfileSave As New IO.StreamWriter(txtpathtarget.Text, True)
            myfileSave.Write(Line)
            myfileSave.Close()
            progbar2.Value += 1

            MessageBox.Show("Substrate completed successfully", "Dict Maker")


        Catch ex As IO.IOException
            MessageBox.Show("Error: " & ex.Message, "Critical error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Catch ex As Exception
            MessageBox.Show("Error: " & ex.Message, "Critical error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally

            myfile.Close()
        End Try

    End Sub


    Private Sub txtpath2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtpath2.TextChanged
        If sender.text <> "" And txtpathtarget.Text <> "" Then
            Button2.Enabled = True
        Else
            Button2.Enabled = False
        End If
    End Sub

    Private Sub txtpathtarget_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtpathtarget.TextChanged
        If sender.text <> "" And txtpath2.Text <> "" Then
            Button2.Enabled = True
        Else
            Button2.Enabled = False
        End If
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Me.Close()

    End Sub

  
    
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ProgBar.Value = 0
        If txtpath.Text = "" Then Exit Sub
        MsgBox(txtpath.Text)
        '-----Open the connection
        Dim con As New OleDb.OleDbConnection
        Dim com As New OleDb.OleDbCommand
        '------
        con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\vbprograms\DictMaker\dict.mdb"

        '----calculate estimates and set the progress bar
        ProgBar.Maximum = CalculateEstimate(txtpath.Text)

        '----
        Dim myfile = New IO.StreamReader(txtpath.Text)
        Try

            '--open the database
            con.Open()

            '---Proceesing the file that contain delimted contents
            Dim Line As String
            Dim AfterSep() As String

            '--------------------Ignore the first 9 lines
            For t As Integer = 1 To 9
                myfile.ReadLine()
            Next t
            '--------------------

            While myfile.Peek > -1
                Application.DoEvents()

                Line = myfile.ReadLine()
                If Line = "</BODY>" Then Exit While
                '----If the carriage return, request next line
                If Line = "" Then Line = myfile.ReadLine()

                AfterSep = Line.Split("@"c)

                '----Build the command and executeit
                com.Connection = con

                com.CommandText = "INSERT INTO dict (word,type,mean) VALUES (?,?,?)"
                com.Parameters.Clear()
                com.Parameters.Add("?", AfterSep(0))
                com.Parameters.Add("?", AfterSep(1))
                com.Parameters.Add("?", AfterSep(2))
                com.ExecuteNonQuery()

                '----Set value progress
                '  If ProgBar.Value = 5136 Then Stop
                ProgBar.Value += 1
                lblprocessed.Text = "Line(s) processed : " & ProgBar.Value

            End While

            MessageBox.Show("Conversion completed successfully", "Dict Maker")

        Catch ex As OleDb.OleDbException
            MessageBox.Show("Error: " & ex.Message, "Critical error", MessageBoxButtons.OK, MessageBoxIcon.Error)

        Catch ex As IO.IOException
            MessageBox.Show("Error: " & ex.Message, "Critical error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Catch ex As Exception
            MessageBox.Show("Error: " & ex.Message, "Critical error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            con.Close()
            myfile.Close()
        End Try

    End Sub

   
    Private Sub btnOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpen.Click
        OFD.FileName = ""
        If OFD.ShowDialog = DialogResult.OK Then
            txtpath.Text = OFD.FileName

        End If
    End Sub

    Private Sub txtpath_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtpath.TextChanged
        If sender.text = "" Then
            Button1.Enabled = False
        Else
            Button1.Enabled = True
        End If
    End Sub
End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

smiling4ever
Web Developer
Syrian Arab Republic Syrian Arab Republic
A Pharmacist Smile | :)

| Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 6 Jun 2005
Article Copyright 2005 by smiling4ever
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid