如果每次单词量不多,建议用左右2列文本框数组,分别输入中、英文,点击完毕后,将文本框数组的值分别存入2个字符串数组(中英文内容在数组中的索引一一对应);如果单词较多,就用2个文本框分别输入中英文,每次用一个事件(比如在输入完英文单词后按回车)来将2个对应的字符串分别存入2个数组中对应的位置,并清空2个文本框以准备再次输入,其它与前相同。
背单词的时候,每一条中文按数组中的索引顺序显示(或增加代码改为随机显示),输入英文后按相同的索引号去英文的数组中找到对应的单词并判断正确与否。
代码:
Private Type WordEnglish As String * 20
Chinese As String * 20
End Type
Private Sub AddWord_Click()
Frame1.Visible = True
List1.Visible = False
End Sub
Private Sub Command1_Click()
Dim Vocabulary As Word
Vocabulary.English = Text1.Text
Vocabulary.Chinese = Text2.Text
Open "C:\Users\Administrator\Desktop\词库.dat" For Random As #1 Len = Len(Vocabulary)
Put #1, LOF(1) / Len(Vocabulary) + 1, Vocabulary
Label3.Caption = "目前词库单词个数:" + CStr(LOF(1) / Len(Vocabulary))
Close #1
Text1.Text = ""
Text2.Text = ""
End Sub
Private Sub Command2_Click()
List1.Clear
Dim Vocabulary As Word
Dim a() As Boolean, n As Integer, RecordID As Integer, k As Integer
Open "C:\Users\Administrator\Desktop\词库.dat" For Random As #1 Len = Len(Vocabulary)
For i = 1 To LOF(1) / Len(Vocabulary)
Get #1, i, Vocabulary
List1.AddItem "(" + CStr(i) + ") " + Trim(Vocabulary.English) + Space(1) + Trim(Vocabulary.Chinese)
Next i
Close #1
List1.Visible = True
End Sub
Private Sub Command3_Click()
List1.Visible = False
End Sub
Private Sub Form_Load()
Frame1.Visible = False
List1.Visible = False
Frame1.Left = 100
Frame1.Top = 100
List1.Left = 100
List1.Top = 100
End Sub
Private Sub Recite_Click()
List1.Clear
Randomize
Frame1.Visible = False
Dim Num As Integer, EnglishWord As String, RightNumber As Integer, VocabularyChinese As String
Num = InputBox("请输入要背诵单词的个数:", "背诵单词", 10)
Dim Vocabulary As Word
Dim a() As Boolean, RecordID As Integer, Counter As Integer
Open "C:\Users\Administrator\Desktop\词库.dat" For Random As #1 Len = Len(Vocabulary)
ReDim a(1 To LOF(1) / Len(Vocabulary))
For i = 1 To LOF(1) / Len(Vocabulary)
a(i) = False
Next i
Do
RecordID = Int(Rnd * (LOF(1) / Len(Vocabulary)) + 1)
If a(RecordID) = False Then
Get #1, RecordID, Vocabulary
For i = 1 To 20
If Mid(Vocabulary.Chinese, i, 1) = " " Then
VocabularyChinese = Left(Vocabulary.Chinese, i - 1)
Exit For
End If
Next i
EnglishWord = InputBox("(" + CStr(Counter + 1) + ")" + Space(1) + Vocabulary.Chinese, "请根据下面出示的中文输入对应的英文单词(共" + CStr(Num) + "个单词)")
If EnglishWord = Trim(Vocabulary.English) Then
RightNumber = RightNumber + 1
List1.AddItem "(" + CStr(Counter + 1) + ")" + Space(1) + VocabularyChinese + Space(1) + "→" + Space(1) + EnglishWord + Space(1) + "√"
Else
List1.AddItem "(" + CStr(Counter + 1) + ")" + Space(1) + VocabularyChinese + Space(1) + "→" + Space(1) + EnglishWord + Space(1) + "×" + Space(1) + Trim(Vocabulary.English)
End If
a(RecordID) = True
Counter = Counter + 1
End If
Loop Until Counter = Num
Label5.Caption = "共默写了" + CStr(Num) + "个单词,其中写对" + CStr(RightNumber) + "个,写错" + CStr(Num - RightNumber) + "个。"
Close #1
List1.Visible = True
End Sub
菜单编辑:
界面设计:
运行界面:
使用控件 Timer1 Label1,label2,label3Private num As Long '用来变换单词用的
Private word() As Variant '单词存放的数组
Private Sub Form_Load()
word() = Array("hello", "world", "I am ", "Visusl", "basic") '这里有一个五个单词的数组
Label1.AutoSize = True '自动调整大小
Timer1.Interval = 100 '调节速度用的
Label1.Caption = word(0)'初始化单词
'字符挨个渐隐效果
With Label2
.Width = Label1.Width
.Height = Label1.Height
.Caption = ""
.Left = 5000
.Top = Label1.Top
End With
With Label3
.Width = Label1.Width
.Height = Label1.Height
.Caption = ""
.Left = 500
.Top = Label1.Top
End With
End Sub
Private Sub Timer1_Timer()
'向左移动
If Label1.Left >500 Then'这里是规定左边界
Label1.Left = Label1.Left - 100 '每次移动100TWip 可以调节
Else
Label1.Left = 5000 '超过左边界后还原位置
num = num + 1 '同时数组的变量+1 起到更改单词的作用
If num = UBound(word) + 1 Then num = 0 '如果单词全部滚动完毕,则重新开始
Label1.Caption = word(num) '更换单词
'根据不同长度的单词来实现隐藏效果
Label2.Width = Label1.Width
Label3.Width = Label1.Width
End If
End Sub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)