网站导航网学 原创论文 原创专题 网站设计 最新系统 原创论文 论文降重 发表论文 论文发表 UI设计定制 论文答辩PPT格式排版 期刊发表 论文专题
返回网学首页
网学原创论文
最新论文 推荐专题 热门论文 论文专题
当前位置: 网学 > 交易代码 > 课程设计 > 正文

VB指法练习的小游戏

论文降重修改服务、格式排版等 获取论文 论文降重及排版 论文发表 相关服务
VB指法练习的小游戏|课程设计|计算机数据库课程设计
Dim sSource(180), sInput(180)
    '分别定义用于存储用户输入和原始文本的字符数组
    Dim i As Integer, iCorrect As Integer, iSecond As Integer
    'iCorrect用于记录用户输入正确的字符数
    'iSecond用于记录已经用去的时间
    Dim n As Integer
    
Private Sub command1_Click()     '提示用户输入用户名
If (Text5.Text = "") Then
MsgBox ("请输入姓名:")
Else
Command2.Enabled = True
Command1.Enabled = False
End If
End Sub
 
Private Sub Command2_Click()   '对用户输入数据进行统计
Command1.Enabled = True
Command2.Enabled = False
iCorrect = 0
 
For i = 1 To 60
sInput(i) = Mid(Text1.Text, i, 1)        '统计第一个text里正确的字符数
 sSource(i) = Mid(Label1.Caption, i, 1)
If sInput(i) = sSource(i) Then
iCorrect = iCorrect + 1
End If
Next
 
For i = 1 To 60                           '统计第二个text里正确的字符数
sInput(i) = Mid(Text2.Text, i, 1)
 sSource(i) = Mid(Label2.Caption, i, 1)
 
If sInput(i) = sSource(i) Then
iCorrect = iCorrect + 1
End If
Next
 
For i = 1 To 60                            '统计第三个text里正确的字符数
sInput(i) = Mid(Text3.Text, i, 1)
 sSource(i) = Mid(Label3.Caption, i, 1)
 
If sInput(i) = sSource(i) Then
iCorrect = iCorrect + 1
End If
Next
'取字符串iCorrect / iSecond中前四个字符
Text4.Text = Mid(iCorrect / iSecond, 1, 4)
 
'取字符串iCorrect * 100 / 180中前四个字符
Text6.Text = Mid(iCorrect * 100 / 180, 1, 4) & "%"
 
'向db1中添加数据
Data1.Recordset.AddNew
Data1.Recordset.Fields("用户名") = Text5.Text
Data1.Recordset.Fields("速度") = Text4.Text
Data1.Recordset.Fields("正确率") = Text6.Text
Data1.Recordset.Fields("难度") = Text7.Text
Data1.Recordset.Update
 
'记时器清零
iSecond = 0
Text5.Text = ""
End Sub
 
Private Sub MSHFlexGrid1_Click()
End Sub
 
Private Sub Command3_Click()
Form2.Show
End Sub
 
Private Sub Command4_Click()
End
End Sub
 
Private Sub Form_Load()
'运行时Command1和Command2不可用
Command1.Enabled = False
 
Command2.Enabled = False
End Sub
 
 
Private Sub Timer1_Timer()
 
iSecond = iSecond + 1   '记时
End Sub
 
Private Sub 困难_Click()  '随机产生33到126之间的字符
Label1.Caption = ""
Label2.Caption = ""
Label3.Caption = ""
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
 Randomize [n]
For i = 1 To 180
 If i < 61 And i > 0 Then    '在label1中产生字符
   If i Mod 6 = 0 Then
                sSource(i) = " "
              Label1.Caption = Label1.Caption & " "
 
                '每隔五个字母就自动产生一个空格
            Else
                sSource(i) = Chr(Int(Rnd() * 93 + 33))
                Label1.Caption = Label1.Caption & sSource(i)
                '随机产生33到126之间的字符
                '并将其加入sSource字符数组中。
 
            End If
            End If
If i < 121 And i > 60 Then     '在label2中产生字符
   If i Mod 6 = 0 Then
                sSource(i) = " "
              Label2.Caption = Label2.Caption & " "
 
                '每隔五个字母就自动产生一个空格
            Else
                sSource(i) = Chr(Int(Rnd() * 93 + 33))
                Label2.Caption = Label2.Caption & sSource(i)
              '随机产生33到126之间的字符母
                '并将其加入sSource字符数组和中。
 
            End If
            End If
If i < 181 And i > 120 Then      '在labe13中产生字符
   If i Mod 6 = 0 Then
                sSource(i) = " "
              Label3.Caption = Label3.Caption & " "
 
                '每隔五个字母就自动产生一个空格
            Else
                sSource(i) = Chr(Int(Rnd() * 93 + 33))
                Label3.Caption = Label3.Caption & sSource(i)
               '随机产生33到126之间的字符
                '并将其加入sSource字符数组。
 
            End If
            End If
 Next
 Text7.Text = "困难"
 Command1.Enabled = True
End Sub
 
Private Sub 容易_Click()
Label1.Caption = ""
Label2.Caption = ""
Label3.Caption = ""
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
 Randomize [n]
For i = 1 To 180
 If i < 61 And i > 0 Then  '在label1中产生字符
   If i Mod 6 = 0 Then
                sSource(i) = " "
              Label1.Caption = Label1.Caption & " "
 
                '每隔五个字母就自动产生一个空格
            Else
          
                sSource(i) = Chr(Int(Rnd() * 25 + 97))
                Label1.Caption = Label1.Caption & sSource(i)
                '随机产生97到122之间的字符
                '并将其加入sSource字符数组。
 
            End If
            End If
If i < 121 And i > 60 Then     '在label2中产生字符
   If i Mod 6 = 0 Then
                sSource(i) = " "
              Label2.Caption = Label2.Caption & " "
 
                '每隔五个字母就自动产生一个空格
            Else
                sSource(i) = Chr(Int(Rnd() * 25 + 97))
                Label2.Caption = Label2.Caption & sSource(i)
                '随机产生97到122之间的字符
                '并将其加入sSource字符数组。
 
            End If
            End If
If i < 181 And i > 120 Then     '在labe13中产生字符
   If i Mod 6 = 0 Then
                sSource(i) = " "
              Label3.Caption = Label3.Caption & " "
 
                '每隔五个字母就自动产生一个空格
            Else
                sSource(i) = Chr(Int(Rnd() * 25 + 97))
                Label3.Caption = Label3.Caption & sSource(i)
                '随机产生97到122之间的字符
                '并将其加入sSource字符数组。
 
            End If
            End If
 Next
 Text7.Text = "容易"
 Command1.Enabled = True
End Sub
 
Private Sub 中等难度_Click()
Label1.Caption = ""
Label2.Caption = ""
Label3.Caption = ""
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
 Randomize [n]
 

For i = 1 To 180
 If i < 61 And i > 0 Then    '在label1中产生字符
   If i Mod 6 = 0 Then
                sSource(i) = " "
              Label1.Caption = Label1.Caption & " "
 
                '每隔五个字母就自动产生一个空格
            Else
                sSource(i) = Chr(Int(Rnd() * 74 + 48))
                Label1.Caption = Label1.Caption & sSource(i)
                '随机产生48到122之间的字符
                '并将其加入sSource字符数组
            End If
            End If
If i < 121 And i > 60 Then     '在label2产生字符
   If i Mod 6 = 0 Then
                sSource(i) = " "
              Label2.Caption = Label2.Caption & " "
                '每隔五个字母就自动产生一个空格
            Else
                sSource(i) = Chr(Int(Rnd() * 74 + 48))
                Label2.Caption = Label2.Caption & sSource(i)
               '随机产生48到122之间的字符
                '并将其加入sSource字符数组。
            End If
            End If
If i < 181 And i > 120 Then      '在label3中产生字符
   If i Mod 6 = 0 Then
                sSource(i) = " "
              Label3.Caption = Label3.Caption & " "
                '每隔五个字母就自动产生一个空格
            Else
                sSource(i) = Chr(Int(Rnd() * 74 + 48))
                Label3.Caption = Label3.Caption & sSource(i)
               '随机产生48到122之间的字符
                '并将其加入sSource字符数组。
            End If
            End If
 Next
 Text7.Text = "中等难度"
 Command1.Enabled = True
End Sub
 
 
 
 
 
 
 
 
 
 
 
 
 
FORM2窗体 代码
 
Private Sub command1_Click()
Key = "Select * from 表1 Order By 速度 desc"    '将数据库中的数据以速度为依据按降序排列
OrderKey = Key
Data1.RecordSource = OrderKey
Data1.Refresh
End Sub
 
 
Private Sub Command2_Click()
If MsgBox("您真的要删除信息吗?", vbYesNo) = vbYes Then  '从第一条开始删除数据库中数据,如果
                                                         '数据全部清空了在提示无信息,如果没有
If Data1.Recordset.EOF Then                              '则可以继续删除
MsgBox "无信息"
Unload Me
Else
Data1.Recordset.MoveFirst
Data1.Recordset.Delete
Data1.Refresh
End If
 
End If
End Sub
设为首页 | 加入收藏 | 网学首页 | 原创论文 | 计算机原创
版权所有 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
Copyright 2008-2020 myeducs.Cn www.myeducs.Cn All Rights Reserved 湘ICP备09003080号 常年法律顾问:王律师