用vb编写一个英文单词背诵系统

如题所述

代码:

Private Type Word
  English 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

菜单编辑:

界面设计:

运行界面:


温馨提示:答案为网友推荐,仅供参考
相似回答