: Public a: Thisform.text1.value=a <大写>:
Thisform.text1.value=upper(a) <小写>:
Thisform.text1.value=lower(a) <复原>: Thisform.text1.value=a
3.班上集体购买课外读物,在文本框中输入3种书的单价、购买数量,计算并输出所用的总金额。 <总计>:
a=val(thisform.text1.value) b=val(thisform.text2.value)
c=val(thisform.text3.value) d=val(thisform.text4.value) e=val(thisform.text5.value) f=val(thisform.text6.value) thisform.text7.value=a*b+c*d+e*f 4. 在文本框中输入小时、分、秒,化成共有多少秒,然后输出之。 a=val(thisform.text1.value) b=val(thisform.text2.value) c=val(thisform.text3.value)
thisform.text4.value=a*3600+b*60+c 5. 编程序输出在指定范围内的3个随机数,范围在文本框中输入。 <三个随机数>:
https://www.sodocs.net/doc/2c237716.html,bel3.caption=str(int((b-a+1)*rand()+a))
https://www.sodocs.net/doc/2c237716.html,bel4.caption=str(int((b-a+1)*rand()+a))
https://www.sodocs.net/doc/2c237716.html,bel5.caption=str(int((b-a+1)*rand()+a))
6.编写例题4-8求圆面积,用对话框输出结果<计算>: r=val(thisform.text1.value)
a=”圆的面积为:”+alltrim(str(3.14*r^2)) messagebox(a,0,”计算圆的面积”) thisform.text1.selstart=0
thisform.text1.sellength=len(thisform.text1.text)
thisform.text1.setfocus
★顺序结构程序
1. 输入3个不同的数,将它们从大到小排序。 <排序>:
a=val(thisform.text1.value) b=val(thisform.text2.value) c=val(thisform.text3.value) do case
case a=max(a,b,c)
thisform.text4.value=alltrim(str(a)) case a=min(a,b,c)
thisform.text6.value=alltrim(str(a)) otherwise
thisform.text5.value=alltrim(str(a)) endcase do case
case b=max(a,b,c)
thisform.text4.value=alltrim(str(b)) case b=min(a,b,c)
thisform.text6.value=alltrim(str(b)) otherwise
thisform.text5.value=alltrim(str(b)) endcase do sase
case c=max(a,b,c)
thisform.text4.value=alltrim(str(c))
case c=min(a,b,c)
thisform.text4.value=alltrim(str(c)) otherwise
thisform.text5.value=alltrim(str(c)) endcase
2. 创建一个检查输入口令的表单,口令设定为“SOFTWARE ”,允许用户输入三次口令。如果三次输入错误,则显示相关信息,并禁止再次输入口令:如果正确,则显示“欢迎使用本系统!”字样,请编写该程序。 <确认>:
a=ALLTRIM(thisform.container1.text1.value) if a=="SOFTWARE"
https://www.sodocs.net/doc/2c237716.html,bel1.caption="欢迎使用本系统!" thisform.container1.visible=.F. https://www.sodocs.net/doc/2c237716.html,bel1.visible=.T. https://www.sodocs.net/doc/2c237716.html,mand1.visible=.t. else b=b+1 if b>=3
messagebox("你已第"+str(b,3)+"次输入错误,"+chr(13); +"不能使用该系统",48,"错误提示") thisform.release ELSE
messagebox("你已第"+str(b,3)+"次输入错误!",48,"错误提示") thisform.container1.text1.selstart=0
thisform.container1.text1.sellength=len(ltrim(thisform.container1.text1.value)) RETURN 0 endif endif
<关闭>: Thisform.release
3. 输入一个数字(0~6),用中英文显示星期几。
<星期转换>: a=thisform.text1.value do case
case a=”0” &&注意带””,字符型 thisform.text2.value=”星期日” thisform.text3.value=”Sunday ” case a=”1”
thisform.text2.value=”星期一” thisform.text3.value=”Monday ” case a=”2”
thisform.text2.value=”星期二” thisform.text3.value=”Tuesday ” case a=”3”
thisform.text2.value=”星期三” thisform.text3.value=”Wednesday ” case a=”4”
thisform.text2.value=”星期四” thisform.text3.value=”Thursday ” case a=”5”
thisform.text2.value=”星期五” thisform.text3.value=”Friday ” case a=”6”
thisform.text2.value=”星期六” thisform.text3.value=”Saturday ” otherwise
messagebox(“对不起,只能输入0-6的整数”,48,”提示”) endcase
thisform.text1.selstart=0 &&以下可不写 thisform.text1.sellength=len(thisform.text1.text) thisform.text1.setfocus
4. 若基本工资大于等于600元,增加工资20%;若小于600元大于等于400元,则增加工资15%;若小于400元则增加工资10%。请根据用户输入的基本工资,计算出增加后的工资。 <新工资>: x=val(thisform.text1.value) do case case x>=600 y=x*1.2
case x<600 and x>=400 y=x*1.15 case x<400 y=x*1.1 endcase
thisform.text2.value=y
5. 输入圆的半径r ,利用选项按钮,选择运算:计算面积、计算周长等。 r=val(thisform.text1.value) n=This.value Do case Case n=1
Y=alltrim(str(2*3.14*r))
A="圆的周长为:"+y Case n=2
Y=alltrim(str(3.14*r^2))
A="圆的面积为:"+y Endcase
https://www.sodocs.net/doc/2c237716.html,bel2.caption=a 6. 设计一个电子游动标题板,标题“使用VFP 设计动画”在表单的黄色区域(容器中)自左至右地反复移动。单击“暂停”按钮,标题停止移动,按钮变成“继续”。 单击“继续”按钮,标题继续移动,按钮又变回“暂停”
<属性>:10 &&动画移动的快慢,数字越大移动越慢 :
If https://www.sodocs.net/doc/2c237716.html,bel1.left+thisform.container1.width<670 &&”670”大于container 的宽度和label 的宽度加和数.即动画要完全过去才能再开始. https://www.sodocs.net/doc/2c237716.html,bel1.left=https://www.sodocs.net/doc/2c237716.html,bel1.left+1 else
https://www.sodocs.net/doc/2c237716.html,bel1.left=-360 &&”-360”绝对值要大于container 的宽度 endif
:
If https://www.sodocs.net/doc/2c237716.html,mand1.caption=”暂停” https://www.sodocs.net/doc/2c237716.html,mand1.caption=”继续” Thisform.container1.timer1.enabled=.f. Else
https://www.sodocs.net/doc/2c237716.html,mand1.caption=”暂停” Thisform.container1.timer1.enabled=.t. Endif
7.设计一个计算一元二次方程根的程序:从文本框输入一元二次方程的三个系数:A
,B ,C ,计算
并输出方程的两个根X1、X2。 当A<>0时,有两个根。 当B*B-4*A*C>0时,有两个不等的实根。
当B*B-4*A*C=0时,有两个相等的实根。
当B*B-4*A*C<0时,有两个不等的虚根。 <求解X>:
a=val(thisform.text1.value) b=val(thisform.text2.value) c=val(thisform.text3.value) m=b^2-4*a*c do case case a=0 x=-c/b
https://www.sodocs.net/doc/2c237716.html,bel4.caption=”该方程不是二次方程,只有一个根,X=”+alltrim(str(x)) otherwise do case case m>0
x1=(-b+sqrt(m))/(2*a) x2=(-b-sqrt(m))/(2*a)
https://www.sodocs.net/doc/2c237716.html,bel4.caption=”该方程有两个不相等的实根,X1=”+alltrim(str())+space(5); +”X2=”+alltrim(str(x2)) Case m=0 X=-b/(2*a)
https://www.sodocs.net/doc/2c237716.html,bel4.caption=”该方程有两个相等的实根,X1=X2=”+alltrim(str(x)) Case m<0
https://www.sodocs.net/doc/2c237716.html,bel4.caption=”该方程有两个不相等的虚根.” Endcase Endcase
4★循环结构程序设计
1. 在列表框中输出100~1000之间能被37整除的数。 <输出>: For n=100 to 1000 If n%37=0
Thisform.list1.additem(alltrim(str(n))) Endif Endfor
<关闭>: Thisform.release
2. 设计程序,求s = 1 + (1 + 2) + (1 + 2 + 3) + … + (1 + 2 + 3 + … + n )的值。 <=><click>:
n=val(thisform.text1.value) m=0 s=0 for i=1 to n if i<=n
m=m+i s=s+m endif endfor
https://www.sodocs.net/doc/2c237716.html,bel3.caption=alltrim(str(s)) thisform.text1.selstart=0
thisform.text1.sellength=len(thisform.text1.text) thisform.text1.setfocus <关闭>: Thisform.release
3. 输出“九九”乘法表,格式如图所示。 <属性>columncount:10 Columnwidth:30,30,30,30,30,30,30,30,30,30(10个) <计算>:
Thisform.list1.additem(“*”) For i=1 to 9
Thisform.list1.addlistitem(alltrim (str(i,3)),1,i+1)
Thisform.list1.addlistitem(alltrim (str(i,3)),i+1,1) For n =1 to i
Thisform.list1.addlistitem(alltrim(str(n,3)),i+1,n+1) Endfor Endfor
<清空>: Thisform.list1.clear
4.组合框中显示2000-2400年间所有闰年。
<
显示
> For n=2000 to 2400
If n%4=0 and n%100<>0 or n%400=0
https://www.sodocs.net/doc/2c237716.html,bo1.additem(alltrim(str(n)))
https://www.sodocs.net/doc/2c237716.html,bo1.displayvalue=1 &&使第一行总是显示 Endif
Endfor
<关闭>:thisform.release
5.页框:素数页:在列表框中显示2
到1000的所有素数。含7页:列表
框中显示1-200之间所有含7的数据。
素数页:
<显示>:
For n=2 to 1000
S=0
For i=2 to n-1 &&除本身以外
if n%i=0
s=1
exit
endif
endfor
if s=0
this.parent.list1.additem(alltrim(str(n)))
endif
endfor
含7页:
<显示>:
FOR n=1 to 200
If “7”$ str(n)
This.parent.list1.additem(alltrim(str(n))) Endif Endfor
5★索引,表单中使用数据表
4. 设计一个操作数据表的表单,使之具有按记录浏览数据表的功能(首记录、上一个、下一个、尾记录)<首记录>: Go top
https://www.sodocs.net/doc/2c237716.html,ma nd1.enabled=.f.
https://www.sodocs.net/doc/2c237716.html,ma nd2.enabled=.f.
https://www.sodocs.net/doc/2c237716.html,ma nd3.enabled=.t.
https://www.sodocs.net/doc/2c237716.html,ma nd4.enabled=.t. Thisform.refresh <上一个>: Skip -1 If recno=1
https://www.sodocs.net/doc/2c237716.html,mand1.enabled=.f. https://www.sodocs.net/doc/2c237716.html,mand2.enabled=.f. Endif
https://www.sodocs.net/doc/2c237716.html,mand3.enabled=.t. https://www.sodocs.net/doc/2c237716.html,mand4.enabled=.t. Thisform.refresh
<下一个>: Skip 1 If eof()=0
Go bottom
https://www.sodocs.net/doc/2c237716.html,mand3.enabled=.f. https://www.sodocs.net/doc/2c237716.html,mand4.enabled=.f. Endif
https://www.sodocs.net/doc/2c237716.html,mand1.enabled=.t. https://www.sodocs.net/doc/2c237716.html,mand2.enabled=.t. Thisform.refresh <尾记录>: Go bottom
https://www.sodocs.net/doc/2c237716.html,mand1.enabled=.t. https://www.sodocs.net/doc/2c237716.html,mand2.enabled=.t. https://www.sodocs.net/doc/2c237716.html,mand3.enabled=.f. https://www.sodocs.net/doc/2c237716.html,mand4.enabled=.f. Thisform.refresh <关闭>: Thisform.release
6★多表操作 7★数组
1. 有一个8×6的矩阵,各元素的值由由计算机随机产生,求全部元素的平均值,并输出高于平均值的元素以及它们的行、列号。 <属性>:column count 6 Column widths:30,30,30,30,30,30 Row source: a
Row source type: 5-
数组
:
Public a(8,6) For i=1 to 48
a(i)=alltrim(str(rand()*100))
Thisform.list1.numberofelements=48 &&在list 中设随机数矩阵 Endfor
: P=”” K=this.value Do case Case k=1 S=0 For i=1 to 48 S=s+val(a(i)) Endfor Av=s/48
https://www.sodocs.net/doc/2c237716.html,bel2.caption=”平均值为:”+alltrim(str(av)) For m=1 to 8 For n=1to 6 If a(i)>av
P=p+”a(“+str(a(m,1))+”,”+str(a(1,n))+”)=”+alltrim (a(m,n))+”,” && a(m,n)=x 中m 和n 必须加上str endif endfor endfor
messagebox(p,0,”大于平均值的元素为:”) Case k=2 Thisform.activate Thisform.refresh
https://www.sodocs.net/doc/2c237716.html,bel2.caption=”平均值为:” &&<重置>
Endcase
2. 求方阵(6×6)的两个对角线元素和。 属性:column count :6 Column
widths:30,30,30,30,30,30 Rowsource: a
RowsourceType:5-数组