记忆力测试VB代码_第1页
记忆力测试VB代码_第2页
记忆力测试VB代码_第3页
记忆力测试VB代码_第4页
记忆力测试VB代码_第5页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、modulel public grade() as byte, yourname() as string form1 dim n as byte 保存显示的字母个数dim i as byte i 保存当前所记忆的字母数dim a() as string 保存随机显示的各个字母dim b as byte 记录当前以输入字母的个数dim w() as byte w 数组保存错误字母的控件下标private sub command1_click() label2.caption = 记住下列每个字母 显示字母时标签2 的内容改变if command1.caption = 开始 then 判断是否为第

2、一次单击command1,是第一次, 则执行“开始”command1.enabled = false command2.enabled = false label3(0).caption = chr(65 + rnd25) i = 2 redim a(0 to 2) a(0) = label3(0).caption timer1.enabled = true else 不是第一次单击,执行“重复本步”call yubei timer1.enabled = true end if end sub private sub command2_click() command2 为“重头开始”按钮red

3、im a(0 to 2) call yubei i = 2 重新赋予初始值timer1.enabled = true end sub private sub command3_click() 结束程序unload form1 end end sub private sub command3_keypress(keyascii as integer) if timer1.enabled = true then exit sub 在显示字母时不响应static x as byte x = 0 if keyascii 122 then keyascii = 0 非字母键和backspace不做响应i

4、f keyascii 8 and keyascii 90 and keyascii 97 then keyascii = 0 if b = 65 and keyascii = 90 then 输入字母label3(b).caption = chr(keyascii) b = b + 1 line3.x1 = line3.x1 + 1100 line3.x2 = line3.x2 + 1100 end if if b = 97 and keyascii = 122 then 将小写转换为大写label3(b).caption = chr(keyascii - 32) b = b + 1 line

5、3.x1 = line3.x1 + 1100 line3.x2 = line3.x2 + 1100 end if if keyascii = 8 then 按 backspace删除一个字母if b = 0 then 没有输入一个字母时,backspace 无效exit sub else label3(b - 1).caption = line3.x1 = line3.x1 - 1100 line3.x2 = line3.x2 - 1100 b = b - 1 end if end if if label3(i).caption = then 判断最后一个字母是否输入exit sub else

6、 line3.visible = false timer2.enabled = false for j = 0 to i if a(j) label3(j).caption then 对输入的字母进行判断x = 1 若比较不一样,x 则为 1,全部正确则为0 s = s + 1 redim preserve w(1 to s) w(s) = j w 数组保存错误字母的控件下标end if next if x = 0 then 输入完全正确for m = 1 to i unload label3(m) unload shape1(m) unload shape2(m) next i = i +

7、1 记忆字母的个数增加1 label3(0).visible = false shape1(0).visible = false shape2(0).visible = false label3(0).caption = chr(65 + rnd * 25) 随机产生第一个字母redim a(0 to i) a(0) = label3(0).caption label2.caption = 记住下列每个字母 timer1.enabled = true 输入正确后,又开始逐个显示字母line3.x1 = 350 line3.x2 = 350 else 输入不完全正确label2.caption

8、= 输入错误,多数人能记忆七个字母,回车重新进行当步测试 label5.caption = 正确的字母序列应为: command1.enabled = true command2.enabled = true command1.setfocus 将键盘输入焦点放在“重复本步”上command1.caption = 重复本步 label4(0).caption = a(0) 以下语句用来显示正确的字母label4(0).visible = true shape3(0).visible = true shape4(0).visible = true for k = 1 to i load labe

9、l4(k) load shape3(k) load shape4(k) label4(k).caption = a(k) label4(k).left = label3(k).left shape3(k).move shape3(k - 1).left + 1100 shape4(k).move shape4(k - 1).left + 1100 label4(k).visible = true shape3(k).visible = true shape4(k).visible = true next for k = 1 to ubound(w) 将输入错误的字母突出显示label4(w(k

10、).forecolor = vbred next end if end if end sub private sub form_unload(cancel as integer) open app.path & pai.txt for append as 1 if i = 2 then i = 0 write #1, form2.text1.text, i end sub private sub sort_click() form3.show form1.hide end sub private sub timer1_timer() 此事件用来逐个显示随机字母static k as b

11、yte 使刚开始停顿一下,然后再显示字母if k = 0 then k = 1 label3(0).visible = true shape1(0).visible = true shape2(0).visible = true exit sub else dim x as byte n = n + 1 if n = i then load label3(n) load shape1(n) load shape2(n) label3(n).left = label3(n - 1).left + 1100 shape1(n).move shape1(n - 1).left + 1100 shap

12、e2(n).move shape2(n - 1).left + 1100 x = 65 + rnd * 25 label3(n).caption = chr(x) a(n) = label3(n).caption label3(n).visible = true shape1(n).visible = true shape2(n).visible = true else k = 0: n = 0: b = 0 timer1.enabled = false for j = 0 to i label3(j).caption = next label2.caption = 凭记忆,依次输入刚才显示的

13、字母 line3.visible = true 显示直线timer2.enabled = true 使直线闪烁,变为光标end if end if end sub private sub timer2_timer() 产生一个光标if line3.visible = true then line3.visible = false else line3.visible = true end if end sub private sub yubei() label4(0).forecolor = vbgreen 将标签 4 控件数组的文本颜色设为绿色label5.caption = command

14、1.enabled = false command2.enabled = false label2.caption = 记住下列每个字母 label3(0).visible = false shape1(0).visible = false shape2(0).visible = false label4(0).visible = false shape3(0).visible = false shape4(0).visible = false line3.x1 = 350 line3.x2 = 350 label3(0).caption = chr(65 + rnd * 25) 随机产生第一

15、个字母a(0) = label3(0).caption for m = 1 to i unload shape1(m) unload shape2(m) unload shape3(m) unload shape4(m) unload label3(m) unload label4(m) next end sub form2 option base 1 private sub command1_click() form2.hide form1.show end sub private sub form_load() dim n as byte open app.path & pai.t

16、xt for input as 1 if lof(1) = 0 then close 1: exit sub do while eof(1) = false n = n + 1 redim preserve grade(n) redim preserve yourname(n) input #1, yourname(n) input #1, grade(n) loop call sort(grade, yourname) for n = 1 to ubound(grade) s = s & 姓名 : & yourname(n) & space(20 - len(your

17、name(n) _ & 成绩 : & grade(n) & chr(13) & chr(10) next form3.text1 = s close 1 end sub private sub text1_change() command1.enabled = true end sub private function sort(a() as byte, b() as string) 对成绩进行排名dim i as integer, j as integer dim m as integer, n as integer m = lbound(a): n = ubound(a) for i = n to m + 1 step -1 for j = m to i - 1 if a(j) a(j + 1) then t = a(j) s = b(j) a(j) = a(j +

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论