1.一元二次方程求解
Form1.Init:
thisform.text1.value=0
thisform.text2.value=0
thisform.text3.value=0
Command1.Click:
a=thisform.text1.value
b=thisform.text2.value
c=thisform.text3.value
if a=0
messagebox('方程无意义')
else
if b^2-4*a*c<0
messagebox('方程无实根')
else
x1=(-b+sqrt(b^2-4*a*c))/(2*a)
x2=(-b-sqrt(b^2-4*a*c))/(2*a)
thisform.text4.value=x1
thisform.text5.value=x2
endif
endif
Command2.Click:
thisform.release
2.登录窗口设计
Form1.Init:
thisform.text2.passwordchar='*'
Command1.Click:
if alltrim(thisform.text1.value)=='USER' and alltrim(thisform.text2.value)=='SQL' messagebox("欢迎")
else
messagebox("错误")
endif
Command2.Click:
thisform.release
3.学生登录
Form1.Init:
thisform.text2.passwordchar='*'
Command1.Click:
locate for alltrim(thisform.text1.value)==alltrim(姓名) and
alltrim(thisform.text2.value)==alltrim(学号)
if found()
messagebox('欢迎')
else
messagebox('错误')
endif
Command2.Click:
thisform.release
4.三次口令,属性窗口设置passwordchar
Form1.Init:
Thisform.ct=0
Text1.Valid:
If alltrim(thisform.text1.value)==?123456?
Messagebox(…正确?)
Else
Thisform.ct=thisform.ct+1
messagebox(“第”+alltrim(str(thisform.ct))+”次错误”)
if thisform.ct=3
thisform.text1.enabled=.f.
endif
endif
Command1.Click:
Thisform.release
5.三角形面积
Form1.Init:
thisform.text1.value=0
thisform.text2.value=0
thisform.text3.value=0
Command1.Click:
a=thisform.text1.value
b=thisform.text2.value
c=thisform.text3.value
if a>0 and b>0 and c>0 and a+b>c and b+c>a and a+c>b s=(a+b+c)/2
s1=sqrt(s*(s-a)*(s-b)*(s-c))
thisform.text4.value=s1
else
messagebox(…不能构成三角形?)
endif
Command2.Click:
Thisform.release
6.计算圆面积
Form1.Init:
thisform.text1.value=0
Command1.Click:
r=thisform.text1.value
if r<=0
messagebox('半径必须是正数')
else
x1=3.14*r^2
thisform.text2.value=x1
endif
Command2.Click:
Thisform.release
7.文本框字体、字型设置
Optiongroup1.click:
do case
case this.value=1
thisform.text1.fontname='宋体'
case this.value=2
thisform.text1.fontname='楷体_GB2312' case this.value=3
thisform.text1.fontname='隶书'
endcase
check1.click:
thisform.text1.fontbold= this.value
check2.click:
thisform.text1.fontitalic= this.value
check3.click:
thisform.text1.fontunderline=this.value
8.求解正方体
Form1.Init:
thisform.caption='正方体计算'
https://www.doczj.com/doc/4a5423422.html,bel1.caption='请输入正方体边长'
thisform.optiongroup1.option1.caption='总边长'
thisform.optiongroup1.option2.caption='表面积'
thisform.optiongroup1.option3.caption='体积'
https://www.doczj.com/doc/4a5423422.html,bel2.caption=''
https://www.doczj.com/doc/4a5423422.html,mand1.caption='计算'
https://www.doczj.com/doc/4a5423422.html,mand2.caption='退出'
thisform.text1.value=0
Command1.Click:
r=thisform.text1.value
x1=thisform.optiongroup1.value
x2=?正方体?
if !empty(r)
do case
case x1=1
https://www.doczj.com/doc/4a5423422.html,bel2.caption=x2+"总周长="+alltrim(str(12*r)) case x1=2
https://www.doczj.com/doc/4a5423422.html,bel2.caption=x2+"表面积="+alltrim(str(6*r*r)) case x1=3
https://www.doczj.com/doc/4a5423422.html,bel2.caption=x2+"体积="+alltrim(str(r*r*r)) endcase
endif
Command2.Click:
Thisform.release
9.文字水平移动:新建属性b
Timer1.Timer:
if https://www.doczj.com/doc/4a5423422.html,bel1.left=0
thisform.b=.f.
endif
if https://www.doczj.com/doc/4a5423422.html,bel1.left=https://www.doczj.com/doc/4a5423422.html,bel1.width
thisform.b=.t.
endif
if thisform.b=.f.
https://www.doczj.com/doc/4a5423422.html,bel1.left=https://www.doczj.com/doc/4a5423422.html,bel1.left+1 else
https://www.doczj.com/doc/4a5423422.html,bel1.left=https://www.doczj.com/doc/4a5423422.html,bel1.left-1 endif
10.百分之一秒计时器
Form1.Init:
thisform.timer1.enabled=.f.
thisform.timer1.interval=10
thisform.text1.value='00:00'
public mm, m
Command1. Click:
thisform.timer1.enabled=.t.
store 0 to mm, m
Command2. Click:
thisform.timer1.enabled=.f.
Command3. Click:
thisform.timer1.enabled=.f.
thisform.text1.value='00:00'
Timer1. Timer:
mm=mm+1
if mm=100
m=m+1
mm=0
endif
mm1=iif(mm<10,"0"+str(mm,1),str(mm,2))
m1=iif(m<10,"0"+str(m,1),str(m,2))
thisform.text1.value=m1+":"+mm1
11.24秒倒计时
Form1.Init:
thisform.timer1.enabled=.f.
thisform.timer1.interval=1000
thisform.text1.value=24
https://www.doczj.com/doc/4a5423422.html,mand1.setfocus
Command1. Click:
thisform.timer1.enabled=.t.
Command2. Click:
thisform.timer1.enabled=.f.
Timer1.Timer:
thisform.text1.value=thisform.text1.value-1
if thisform.text1.value=0
https://www.doczj.com/doc/4a5423422.html,mand1.enabled=.f.
thisform.timer1.enabled=.f.
endif
12.电子时钟
Form1. Init:
thisform.timer1.enabled=.t.
thisform.timer1.interval=1000
Timer1. Timer:
thisform.text1.value=substr(time(),1,2)
thisform.text2.value=substr(time(),4,2)
thisform.text3.value=substr(time(),7,2)
13.信息窗
Timer1.Timer:
thisform.text1.value=time()
t=val(substr(time(),7,2))
if t%2=0
thisform.backcolor=rgb(0,2,255)
else
thisform.backcolor=rgb(0,255,0)
endif
14.小球左右移动,说明:小球填充色(非背景色:backcolor)为红色,本题需
要设置fillcolor、fillstyle属性,设置shape1的curvature等于99,其height、width为50。表单新建属性dx,其值为5。以上内容全部在属性窗口完成。
Timer1. Timer:
if thisform.shape1.left<=0
thisform.dx=5
endif
if thisform.shape1.left>=thisform.width-thisform.shape1.width
thisform.dx=-5
endif
thisform.shape1.left=thisform.shape1.left+thisform.dx
15.标签上下移动,新建属性down,在属性窗口设置其初值为.t.(初
始向下运动)。
Timer1. Timer:
if https://www.doczj.com/doc/4a5423422.html,bel1.top=0
thisform.down=.t.
endif
if https://www.doczj.com/doc/4a5423422.html,bel1.top=https://www.doczj.com/doc/4a5423422.html,bel1.height thisform.down=.f.
endif
if thisform.down=.t.
https://www.doczj.com/doc/4a5423422.html,bel1.top=https://www.doczj.com/doc/4a5423422.html,bel1.top+1
else
https://www.doczj.com/doc/4a5423422.html,bel1.top=https://www.doczj.com/doc/4a5423422.html,bel1.top-1
endif
16.日历时钟
Form1. Init:
thisform.setall(…readonly?,.t.,?textbox?)
public c
c='日一二三四五六'
thisform.text1.dateformat=14
thisform.text1.value=date()
thisform.text2.value='星期'+substr(c,2*dow(date())-1,2)+'('+cdow(date())+')'
thisform.text3.value=time()
Spinner1. Upclick:
thisform.text1.value=thisform.text1.value+1
thisform.text2.value='星期'+substr(c,2*dow(thisform.text1.value)-1,2)
+'('+cdow(thisform.text1.value)+')'
Spinner1. Downclick:
thisform.text1.value=thisform.text1.value-1
thisform.text2.value='星期'+substr(c,2*dow(thisform.text1.value)-1,2)
+'('+cdow(thisform.text1.value)+')'
Timer1. Timer:
Thisform.text1.value=time()
17.班级平均成绩
Form1. Init:
https://www.doczj.com/doc/4a5423422.html,bo1.style=2
index on left(学号,3) to xh unique
scan
thisform. combo1. additem(left(学号,3))
endscan
set index to
Combo1. Interactivechange:
set talk off
average 成绩to x for left(学号,3)=alltrim(https://www.doczj.com/doc/4a5423422.html,bo1.value)
thisform.text1.value=x
set talk on
18.编制一个显示指定班级的平均成绩的表单,要求:通过属性窗口设置以下属
性:表单、标签、命令按钮的标题属性,标签的字体为默认值。
Form1.Init:
set talk off
select 学生
index on left(学号,3) to xh unique
https://www.doczj.com/doc/4a5423422.html,bo1.rowsourcetype=0
scan
https://www.doczj.com/doc/4a5423422.html,bo1.additem(left(学号,3))
endscan
set index to
Command1.Click:
select 成绩
average 成绩to zpjcj for left(alltrim(学号),3)==
alltrim(https://www.doczj.com/doc/4a5423422.html,bo1.displayvalue)
thisform.text1.value=zpjcj
thisform.refresh
Command2.Click:
Thisform.release
Combo1.Valid:
select 学生
if empty(this.displayvalue)
return .t.
endif
locate for left(alltrim(学号),3)==left(alltrim(this.displayvalue),3)
if eof()
return .f.
else
return .t.
endif
19.编制一个显示指定班级的奖学金总额的表单,要求:通过属性窗口设置以下
属性:表单、标签、命令按钮的标题属性,标签的字体为默认值。
Form1.Init:
Set talk off
Thisform. combo1.style=2
index on left(学号,3) to xh unique
https://www.doczj.com/doc/4a5423422.html,bo1.rowsourcetype=0
scan
https://www.doczj.com/doc/4a5423422.html,bo1.additem(left(学号,3))
endscan
set index to
Combo1.Interactivechange:
sum 奖学金to s for left(学号,3)==alltrim(https://www.doczj.com/doc/4a5423422.html,bo1.displayvalue)
thisform.text1.value=s
Command1.Click:
thisform.release
20.编制显示指定班级的奖学金总额的表单
Form1.Init:
set talk off
index on left(学号,3) to xh unique
https://www.doczj.com/doc/4a5423422.html,bo1.rowsourcetype=0
scan
https://www.doczj.com/doc/4a5423422.html,bo1.additem(left(学号,3))
endscan
set index to
Command1.Click:
locate for left(学号,3)==left(alltrim(https://www.doczj.com/doc/4a5423422.html,bo1.displayvalue),3)
if found()
sum 奖学金to s for left(学号,3)==left(alltrim(https://www.doczj.com/doc/4a5423422.html,bo1.displayvalue),3)
thisform.text1.value=s
else
thisform.text1.value='无此班级'
endif
说明:比较17-20题,设置https://www.doczj.com/doc/4a5423422.html,bo1.style=2时,为下拉列表框,不允许用户输入,所以用户选定的班级存在。当为下拉组合框时,允许用户输入,采用了两种方法判断用户输入的班级是否存在,一种如题18,Combo1.Valid,用户输入的班级不存在,用户需重新输入;一种如题20,Command1.Click,用户输入的班级不存在,则输出“无此班级”。
21.输出指定表的全部字段(此题数据环境不添加表)
Form1.Init:
https://www.doczj.com/doc/4a5423422.html,bel2.visible=.f.
thisform.list1.visible=.f.
Text1.Valid:
fn=alltrim(this.value)+'.dbf'
if file(fn)
thisform.setall('visible',.t.)
thisform.list1.clear
use (fn)
for i=1 to fcount()
thisform.list1.additem(field(i))
endfor
else
https://www.doczj.com/doc/4a5423422.html,bel2.visible=.f.
thisform.list1.visible=.f.
messagebox('指定的表文件不存在',64,'表文件存在判断') endif
22.时钟及表浏览(为表单新建属性clock)
Form1.Init:
thisform.setall('readonly',.t.,'textbox')
thisform.text1.readonly=.f.
go top
https://www.doczj.com/doc/4a5423422.html,mand2.enabled=.f.
Command1.Click:
thisform.clock=.t.
thisform.timer1.interval=1000
https://www.doczj.com/doc/4a5423422.html,mand1.enabled=.f.
https://www.doczj.com/doc/4a5423422.html,mand2.enabled=.t.
Command2.Click:
thisform.clock=.f.
thisform.timer1.interval=2000
https://www.doczj.com/doc/4a5423422.html,mand1.enabled=.t.
https://www.doczj.com/doc/4a5423422.html,mand2.enabled=.f.
Timer1.Timer:
if thisform.clock=.f.
skip
if eof()
go top
endi f
else
thisform.text1.value=time()
endif
thisform.refresh