⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 word.vb

📁 用VB.NET编写的简单英汉查询小程序。
💻 VB
字号:
Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows 窗体设计器生成的代码 "

    Public Sub New()
        MyBase.New()

        '该调用是 Windows 窗体设计器所必需的。
        InitializeComponent()

        '在 InitializeComponent() 调用之后添加任何初始化

    End Sub

    '窗体重写 dispose 以清理组件列表。
    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

    'Windows 窗体设计器所必需的
    Private components As System.ComponentModel.IContainer

    '注意: 以下过程是 Windows 窗体设计器所必需的
    '可以使用 Windows 窗体设计器修改此过程。
    '不要使用代码编辑器修改它。
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
    Friend WithEvents Button2 As System.Windows.Forms.Button
    Friend WithEvents Button3 As System.Windows.Forms.Button
    Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
    Friend WithEvents Button4 As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
        Me.Label1 = New System.Windows.Forms.Label
        Me.Button1 = New System.Windows.Forms.Button
        Me.TextBox1 = New System.Windows.Forms.TextBox
        Me.ListBox1 = New System.Windows.Forms.ListBox
        Me.Button2 = New System.Windows.Forms.Button
        Me.Button3 = New System.Windows.Forms.Button
        Me.TextBox2 = New System.Windows.Forms.TextBox
        Me.Button4 = New System.Windows.Forms.Button
        Me.SuspendLayout()
        '
        'Label1
        '
        Me.Label1.AutoSize = True
        Me.Label1.BackColor = System.Drawing.Color.FromArgb(CType(192, Byte), CType(192, Byte), CType(255, Byte))
        Me.Label1.Font = New System.Drawing.Font("宋体", 10.5!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
        Me.Label1.ForeColor = System.Drawing.Color.Green
        Me.Label1.Location = New System.Drawing.Point(16, 16)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(128, 19)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "请输入相应的单词:"
        Me.Label1.TextAlign = System.Drawing.ContentAlignment.BottomRight
        '
        'Button1
        '
        Me.Button1.BackColor = System.Drawing.Color.FromArgb(CType(224, Byte), CType(224, Byte), CType(224, Byte))
        Me.Button1.Font = New System.Drawing.Font("宋体", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
        Me.Button1.ForeColor = System.Drawing.Color.Green
        Me.Button1.Location = New System.Drawing.Point(152, 48)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(72, 24)
        Me.Button1.TabIndex = 1
        Me.Button1.Text = "搜索 "
        '
        'TextBox1
        '
        Me.TextBox1.Location = New System.Drawing.Point(168, 16)
        Me.TextBox1.Multiline = True
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.Size = New System.Drawing.Size(144, 24)
        Me.TextBox1.TabIndex = 2
        Me.TextBox1.Text = ""
        '
        'ListBox1
        '
        Me.ListBox1.ItemHeight = 12
        Me.ListBox1.Location = New System.Drawing.Point(8, 48)
        Me.ListBox1.Name = "ListBox1"
        Me.ListBox1.Size = New System.Drawing.Size(136, 208)
        Me.ListBox1.TabIndex = 7
        '
        'Button2
        '
        Me.Button2.BackColor = System.Drawing.Color.FromArgb(CType(224, Byte), CType(224, Byte), CType(224, Byte))
        Me.Button2.Font = New System.Drawing.Font("宋体", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
        Me.Button2.ForeColor = System.Drawing.Color.Green
        Me.Button2.Location = New System.Drawing.Point(152, 104)
        Me.Button2.Name = "Button2"
        Me.Button2.Size = New System.Drawing.Size(72, 24)
        Me.Button2.TabIndex = 11
        Me.Button2.Text = "增加"
        '
        'Button3
        '
        Me.Button3.BackColor = System.Drawing.Color.FromArgb(CType(224, Byte), CType(224, Byte), CType(224, Byte))
        Me.Button3.Font = New System.Drawing.Font("宋体", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
        Me.Button3.ForeColor = System.Drawing.Color.Green
        Me.Button3.Location = New System.Drawing.Point(152, 216)
        Me.Button3.Name = "Button3"
        Me.Button3.Size = New System.Drawing.Size(72, 24)
        Me.Button3.TabIndex = 12
        Me.Button3.Text = "删除"
        '
        'TextBox2
        '
        Me.TextBox2.Location = New System.Drawing.Point(235, 48)
        Me.TextBox2.Multiline = True
        Me.TextBox2.Name = "TextBox2"
        Me.TextBox2.Size = New System.Drawing.Size(136, 208)
        Me.TextBox2.TabIndex = 13
        Me.TextBox2.Text = "TextBox2"
        '
        'Button4
        '
        Me.Button4.BackColor = System.Drawing.Color.FromArgb(CType(224, Byte), CType(224, Byte), CType(224, Byte))
        Me.Button4.Font = New System.Drawing.Font("宋体", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
        Me.Button4.ForeColor = System.Drawing.Color.Green
        Me.Button4.Location = New System.Drawing.Point(152, 160)
        Me.Button4.Name = "Button4"
        Me.Button4.Size = New System.Drawing.Size(72, 24)
        Me.Button4.TabIndex = 14
        Me.Button4.Text = "修改"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.BackColor = System.Drawing.SystemColors.Control
        Me.BackgroundImage = CType(resources.GetObject("$this.BackgroundImage"), System.Drawing.Image)
        Me.ClientSize = New System.Drawing.Size(379, 264)
        Me.Controls.Add(Me.Button4)
        Me.Controls.Add(Me.TextBox2)
        Me.Controls.Add(Me.Button3)
        Me.Controls.Add(Me.Button2)
        Me.Controls.Add(Me.ListBox1)
        Me.Controls.Add(Me.TextBox1)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.Label1)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.MaximizeBox = False
        Me.Name = "Form1"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "高效英汉字典查询系统"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Public fname1 As String = "英汉词典.txt" '文本名
    Public word(6500, 1) As String          '定义一个二维数组
    Public cs As Integer = 0                 '记录数据库里 单词个数

    'OKOKOKOKOKOKOK******************************************************
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim aspect As String
        Dim load As Integer     '记录 单词长度
        Dim i As Integer = 0    '数组 开始位置
        Dim n As String         '临时记录 读出的单词
        Dim m As String         '临时记录 读出单词的中文解释
        Dim changdu As Integer  '计算单词后面剩下的字符串的长度。
        TextBox1.Text = ""
        TextBox2.Text = ""

        FileOpen(1, fname1, OpenMode.Input)   '打开文件,在此用的是相对路径。
        Do While Not EOF(1)
            aspect = LineInput(1)
            load = InStr(aspect, " ")         '查找空格在字符串中的位子。
            n = Microsoft.VisualBasic.Left(aspect, load - 1) '截取空格字符:即单词
            word(i, 0) = n                    '存单词
            ListBox1.Items.Add(n)
            changdu = Len(aspect) - load
            m = Trim(Microsoft.VisualBasic.Right(aspect, changdu))   '将剩下的字符串赋给变量m。
            word(i, 1) = m                    '存中文解释
            i = i + 1
        Loop
        cs = i
        FileClose(1)
    End Sub

    '选择******************************************************
    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
        Try
            TextBox1.Text = word(ListBox1.SelectedIndex, 0)
            TextBox2.Text = Trim(word(ListBox1.SelectedIndex, 1))
        Catch ex As Exception
            Exit Sub
        End Try
    End Sub

    '搜寻******************************************************
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim i As Integer = -1   '从数组开始查询
        If TextBox1.Text = "" Then
            MessageBox.Show("搞什么啊,巧妇也难做无米之炊啊!")
            TextBox2.Text = ""
            TextBox1.Focus()
            Exit Sub
        Else
            For i = i + 1 To cs
                If LCase(TextBox1.Text) = LCase(word(i, 0)) Then
                    TextBox2.Text = Trim(word(i, 1))
                    Exit Sub
                End If
            Next
            MessageBox.Show("哎,没得办法了,看样子你要自己猜啦!")
        End If
    End Sub

    '添加******************************************************
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim i As Integer = 0
        Dim j, k As Integer
        Dim English, ch, aspect As String

aa:     English = InputBox("请输入想要添加的单词!", "单词添加")  '先输入单词(English)
        If English = "" Then
            MessageBox.Show("不输入单词,怎么找单词呢??")
            GoTo aa
        End If
bb:     ch = InputBox("请输入中文意思!", "单词添加")         '输入中文意思
        If ch = "" Then
            MessageBox.Show("没的解释怎么查翻译啊,快输入中文翻译!")
            GoTo bb
        End If

        Do While LCase(word(i, 0)) < LCase(English)
            i = i + 1
            If cs = i Then                         '如果找完数据库 在最后添加
                word(i, 0) = English               '把增加的单词赋给I的位置
                word(i, 1) = ch                    '把增加的单词中文赋给I的位置
                cs = cs + 1

                FileOpen(1, fname1, OpenMode.Output)  '打开文件
                For i = 0 To cs - 1
                    PrintLine(1, word(i, 0) & " " & word(i, 1))  '把数组里的单词重新写一遍
                Next
                ListBox1.Items.Clear()
                FileClose(1)                           '文件关闭

                ListBox1.Items.Clear()
                Form1_Load(sender, e)

                MessageBox.Show("恭喜啊,添加成功啦!")
                Exit Sub
            End If
        Loop
        If LCase(word(i, 0)) = LCase(English) Then      '如果 库里有 退出
            MessageBox.Show("库里已经有这个单词啦!")
            Exit Sub
        Else
            For k = cs To i + 1 Step -1        '向后位移   直到 添加位置 退出循环
                word(k + 1, 0) = word(k, 0)
                word(k + 1, 1) = word(k, 1)
            Next k
            word(i, 0) = English               '把增加的单词赋给I的位置
            word(i, 1) = ch                    '把增加的单词中文赋给I的位置
            cs = cs + 1

            FileOpen(1, fname1, OpenMode.Output)  '打开文件
            For i = 0 To cs - 1
                PrintLine(1, word(i, 0) & " " & word(i, 1))  '把数组里的单词 写入文本
            Next
            FileClose(1)                          '文件关闭

            ListBox1.Items.Clear()
            Form1_Load(sender, e)

            MessageBox.Show("添加成功")
            Exit Sub
        End If

    End Sub

    '修改******************************************************
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Dim ch, aspect As String
        Dim j As Integer
        If -1 = ListBox1.SelectedIndex Then
            MsgBox("单词都没选择,你想修改什么啊??")
            ListBox1.Focus()
            Exit Sub
        End If
aa:     ch = InputBox("请输入修改单词的中文解释!", "修改单词", Trim(word(ListBox1.SelectedIndex, 1)))        '输入中文意思
        If ch = "" Then
            MessageBox.Show("修改你也不能删除以前的解释啊!")
            GoTo aa
        End If
        word(ListBox1.SelectedIndex, 1) = ch
        FileOpen(1, fname1, OpenMode.Output)  '打开文件
        For j = 0 To cs - 1
            PrintLine(1, word(j, 0) & " " & word(j, 1)) '把数组里的单词重新写一遍
        Next
        FileClose(1)                '文件关闭
        MsgBox("你知道你干了什么,真没办法,叫我以后怎么混啊...")
        ListBox1.Items.Clear()
        Form1_Load(sender, e)
    End Sub

    '删除******************************************************
    Private Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim i, j, k As Integer
        k = MsgBox("小心啊,不能随便删,三思而后行啊!", MsgBoxStyle.YesNo)
        If 6 = k Then
            For i = ListBox1.SelectedIndex To cs
                word(i, 0) = word(i + 1, 0)
                word(i, 1) = word(i + 1, 1)
            Next
            cs = cs - 1

            FileOpen(1, fname1, OpenMode.Output)  '打开文件
            For j = 0 To cs - 1
                PrintLine(1, word(j, 0) & " " & word(j, 1)) '把数组里的单词重新写一遍
            Next
            FileClose(1)                '文件关闭
            MsgBox("没得救啦,你把单词删除啦!")
            ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
            ListBox1.Refresh()
            TextBox1.Text = ""
            TextBox2.Text = ""
            Exit Sub
        Else
            Exit Sub
        End If
    End Sub

End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -