'Option Explicit
'菜单“工程腊渗巧喊尘/部件”引用Microsoft windows common controls 5.0
'2个textbox,2个label
'1个Command1,可有可无
'1个ListView1,用于装载英文及对应中文解释,可以加快查询速度
Private Sub Form_Load()
On Error Resume Next
Dim str1 As String, str2
Label1.Caption = "单词"
Label2.Caption = "中文"
Command1.Caption = "查找"
With ListView1
.View = lvwReport
.Visible = False
.ColumnHeaders.Add "中文"
With .ListItems
Open App.Path & "\词库.txt" For Input As #1 '打开文件
While Not EOF(1) '逐行排查核对是否和用户输入的单词一致
Line Input #1, str1
str2 = Split(Trim(str1), ",") '英文单词和中文轮键解释用半角逗号,隔开。 _
中文解释中不要出现半角逗号,要用全角逗号。这样可以使用短语(含有空格) _
可能的话,建议用数据库。如果是空格分开,把","改为" "
If Len(str2(0)) Then
.Add , str2(0), str2(1) 'str2(0)是英文,作为关键字
End If
Wend
Close
End With
End With
Text1.Text = ""
Text2.Text = ""
End Sub
Private Sub Text1_Change()
On Error Resume Next
Dim li As ListItem
Set li = ListView1.ListItems(Trim(Text1))
If li Is Nothing Then
Text2.Text = ""
Else
Text2.Text = li.Text
End If
End Sub
Private Sub Command1_Click()
Call Text1_Change
End Sub
只提供思路:如果每次单词量不多,建议用左右2列文本框数组,分别输入中、英文,点击完毕后,将文本框数组的值分别存入2个字符串数组(中英文内容在数组中的索引一一对应);如果单词敬宴雹较多,就用2个文本框分别输入中英文,每次用一个事件(比如在输入完英文单词后按回车)来亮帆将2个对应的字符串分别存入2个数组中对应的位置,并清空2个文本框以准备祥中再次输入,其它与前相同。
背单词的时候,每一条中文按数组中的索引顺序显示(或增加代码改为随机显示),输入英文后按相同的索引号去英文的数组中找到对应的单词并判断正确与否。
Private Type wordword As String
total As Integer
End Type
Dim a(3000) As word
Dim jishu
Function findword(ss) As Integer
findword = -1
For i = 1 To jishu
If a(i).word = ss Then
findword = i
a(i).total = a(i).total + 1
Exit For
End If
Next i
End Function
Sub insertword(ss)
If findword(ss) = -1 Then
jishu = jishu + 1
a(jishu).word = ss
a(jishu).total = 1
End If
End Sub
Sub paixu()
For i = 1 To jishu - 1
k = i
For j = i + 1 To jishu
If a(k).total <a(j).total Then k = j
Next j
tmp = a(k).total: a(k).total = a(i).total: a(i).total = tmp
tmp = a(k).word: a(k).word = a(i).word: a(i).word = tmp
Next i
End Sub
Private Sub Command1_Click()
Dim str() As String
fn = FreeFile
stri = "蔽虚"
Open "d:\temp.txt" For Input As fn '假设要统孙并带计的是d:\temp.txt文件中的则芦单词
Do While Not EOF(fn)
Line Input #fn, ss
stri = stri &ss
Loop
Close fn
str = Split(stri, " ")
For i = 1 To UBound(str)
ss = Trim(str(i))
If Len(ss) >0 Then
s = Left(ss, 1)
If s >= "A" And s <= "Z" Or s >= "a" And s <= "z" Then
insertword ss
End If
End If
Next i
paixu
For i = 1 To 10
Print a(i).word, a(i).total
Next i
End Sub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)