vb.net字典使用的简单介绍

用VB语言制作英汉小辞典Public Class Form1
Inherits System.Windows.Forms.Form
Public filename As String = "英汉词典.txt"
Public myword(6500, 1) As String
Public words As Integer = 0
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim a As String
Dim b As Integer
Dim i As Integer = 0
Dim n As String
Dim m As String
Dim stringb As Integer
TextBox1.Text = ""
TextBox2.Text = ""
FileOpen(1, "英汉词典.txt", OpenMode.Input)
Do While Not EOF(1)
a = LineInput(1)
b = InStr(a, " ")
n = Microsoft.VisualBasic.Left(a, b - 1)
myword(i, 0) = n
ListBox1.Items.Add(n)
stringb = Len(a) - b
m = Trim(Microsoft.VisualBasic.Right(a, stringb))
myword(i, 1) = m
i += 1
Loop
words = i
FileClose(1)
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 words
If LCase(TextBox1.Text) = LCase(myword(i, 0)) Then
TextBox2.Text = Trim(myword(i, 1))
Exit Sub
End If
Next
MessageBox.Show(" 您需要的单词不存在,请重新输入")
End If
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Try
TextBox1.Text = myword(ListBox1.SelectedIndex, 0)
TextBox2.Text = Trim(myword(ListBox1.SelectedIndex, 1))
Catch ex As Exception
End Try
Exit Sub
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim ch, enterwords As String
Dim j, m As Integer
If -1 = ListBox1.SelectedIndex Then
MsgBox("请选择单词", , "")
ListBox1.Focus()
Exit Sub
End If
enterwords = InputBox("请修改单词", "修改单词", Trim(myword(ListBox1.SelectedIndex, 0)))
Do While enterwords = ""
m = MsgBox("单词不能为空", MsgBoxStyle.RetryCancel, "修改单词")
If m = 4 Then
enterwords = InputBox("请修改单词", "修改单词", Trim(myword(ListBox1.SelectedIndex, 0)))
Else
Exit Sub
End If
Loop
ch = InputBox("请修改中文意思", "修改单词", Trim(myword(ListBox1.SelectedIndex, 1)))
Do While ch = ""
m = MsgBox("中文意思不能为空", MsgBoxStyle.RetryCancel, "修改单词")
If m = 4 Then
ch = InputBox("请修改中文意思", "修改单词", Trim(myword(ListBox1.SelectedIndex, 1)))
Else
Exit Sub
End If
Loop
myword(ListBox1.SelectedIndex, 1) = ch
myword(ListBox1.SelectedIndex, 0) = enterwords
FileOpen(1, filename, OpenMode.Output)
For j = 0 To words - 1
PrintLine(1, myword(j, 0)" "myword(j, 1))
Next
FileClose(1)
MsgBox("修改成功")
ListBox1.Items.Clear()
Form1_Load(sender, e)
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 k, m As Integer
Dim enterwords, ch As String
enterwords = InputBox("请输入要添加的单词", "添加单词")
Do While enterwords = ""
m = MsgBox("单词不能为空,请输入单词!", MessageBoxButtons.RetryCancel, "添加单词")
If m = 4 Then
enterwords = InputBox("请输入要添加的单词", "添加单词")
Else
Exit Sub
End If
Loop
ch = InputBox("请输入中文意思", "添加中文")
Do While ch = ""
m = MsgBox("中文不能为空,请输入中文意思!", MessageBoxButtons.RetryCancel, "添加中文")

推荐阅读