
实验报告
实验名称 表单程序设计
实验项目 使用面向对象程序设计知识设计“计算器”程序
专业班级 姓名 学号
指导教师 王伟勤 成绩 日期 2009-11-5
一、实验目的
1.了解面向对象程序设计的基本概念。
2.掌握常用对象、属性、事件的使用。
3.掌握对象的引用及用代码设置属性的方法。
4.掌握普通表单的设计、调试和运行。
二、实验内容
设计如下图所示的计算器表单程序,并实现要求的功能。
要求:(1)可连续进行算术运算;
(2)当输入新的数学式时,会自动清除文本框的原有内容;
(3)当用户输入的数学式子有误时,可给出相应的提示,并要求重新输入,同时使文本框获得焦点,并将原有内容反选。
三、设计步骤及相关按钮代码
建立一个CommandGroup,按钮数为16,然后编辑对象,排列按钮和调整按钮的大小,然后在Form的Init行为新增声明和快捷对16个按钮的Caption进行修改:
PUBLIC T
T=""
for i=1 to 9
this.commandgroup1.buttons(i).caption=alltrim(str(i))
endfor
this.commandgroup1.buttons(10).caption="0"
this.commandgroup1.buttons(11).caption="*"
this.commandgroup1.buttons(12).caption="+"
this.commandgroup1.buttons(13).caption="-"
this.commandgroup1.buttons(14).caption="="
this.commandgroup1.buttons(15).caption="."
this.commandgroup1.buttons(16).caption="/"
然后统一在CommandGroup的Click行为部署各按钮相应的行为:
do case
case this.value=1
t=t+"1"
thisform.text1.value=t
case this.value=2
t=t+"2"
thisform.text1.value=t
case this.value=3
t=t+"3"
thisform.text1.value=t
case this.value=4
t=t+"4"
thisform.text1.value=t
case this.value=5
t=t+"5"
thisform.text1.value=t
case this.value=6
t=t+"6"
thisform.text1.value=t
case this.value=7
t=t+"7"
thisform.text1.value=t
case this.value=8
t=t+"8"
thisform.text1.value=t
case this.value=9
t=t+"9"
thisform.text1.value=t
case this.value=10
t=t+"0"
thisform.text1.value=t
case this.value=11
t=t+"*"
thisform.text1.value=t
case this.value=12
t=t+'+'
thisform.text1.value=t
case this.value=13
t=t+'-'
thisform.text1.value=t
case this.value=14
thisform.text1.value=alltrim(str(&t,20,6))
case this.value=15
t=t+'.'
thisform.text1.value=t
case this.value=16
t=t+'/'
thisform.text1.value=t
endcase
thisform.refresh
四、运行结果
见程序。
| 五、实验总结(调试分析和体会) |
