带星号的程序代码总结

发布时间:2015-03-25 12:06:49   来源:文档文库   
字号:

3输入三个数逆序显示

m=thisform.text1.value

a=int(m/100)

b=int(mod,100)/10)

c=mod(m,10)

n=100*c+10*b+a

thisform.label2.caption="结果为:"+str(n,3)

4求圆面积显示在标签中

r=thisform.text1.value

s=pi()*r*r

thisform.label2.caption="该圆的面积为:"+str(s,3)

5逆序显示加messagebox

m=thisform.text1.value

a=int(m/100)

b=int(mod,100)/10)

c=mod(m,10)

n=100*c+10*b+a

thisform.label2.caption="结果为:"+str(n,3)

5逆序显示加messagebox

x=thisform.text1.value

if x>=100 and x<=999 and int(x)=x

x1=int(x/100)

x2=int(mod(x,100)/10)

x3=mod(x,10)

y=x3*100+x2*10+x1

thisform.label2.caption="结果为:"+str(y,3)

else

messagebox("入的不是一个三位自然数,请重新输入!")

thisform.text1.value=0

thisform.text1.setfocus

endif

6圆面积messagebox显示

r=thisform.text1.value

s=pi()*r*r

messagebox("圆面积="+str(s,3),0)

8判断能否构成三角形

a=thisform.text1.value

b=thisform.text2.value

c=thisform.text3.value

if a+b>c and a+c>b and b+c>a

l=(a+b+c)/2

area=sqrt(l*(l-a)*(l-b)*(l-c))

thisform.text4.value=round(area,1)

else

messagebox("不能构成三角形,请重新输入!")

thisform.text1.value=0

thisform.text2.value=0

thisform.text3.value=0

thisform.text4.value=0

thisform.text1.setfocus

endif

9判断是否是闰年

D=thisform.text1.value

Y=year(d)

If y/4=int(y/4) and y/100<>int(y/100) or int(y/400)=y/400

Y1=

Else

Y1=不是

Endif

Thisform.label2.caption=y1

10比较大小双分支

a=thisform.text1.value

b=thisform.text2.value

if a>b

thisform.text3.value=a

else

thisform.text3.value=b

endif

11单分支

A=thisform.text1.value

B=thisform.text2.value

If a

A=b

endif

Thisform.text3.value =a

12输入两个数按从大到小输出

A=thisform.text1.value

B=thisfor.text2.value

If a

C=a

A=b

B=c

endif

Thisform.text1.value=a

Thisform.text2.value=b

13输入三个数按从小排列

A=thisform.text1.value

B=thisform.text2.value

C=thisform.text3.value

If a

T=a

A=b

B=t

If a

T=a

A=c

C=t

If b

T=b

B=c

C=t

Endif

Endif

Endif

Thisform.text1.value=a

Thisform.text2.value=b

Thisform.text3.value=c

14季节

m=val(thisform.text1.value)

do case

case m=3 or m=4 or m=5

s="春季"

case m=6 or m=7 or m=8

s="夏季"

case m=9 or m=10 or m=11

s="秋季"

case m=12 or m=1 or m=2

s="冬季"

endcase

thisform.label1.caption="该季节为:"+s

15计算1+100

s=0

i=1

do while i<=100

s=s+i

i=i+1

enddo

Thisform.text1.value=s

16计算N!

P=1

FOR I=1 T0 THISFORM.TEXT1.VALUE

P=p*i

Endfor

Thisform.text2.value=P

18K=1+2^2+..n^2

s=0

for i=1 to val(thisform.text1.value)

s=s+i^2

endfor

thisform.text2.value=s

17计算奇数和

s=0

for i=1to 100 step 2

s=s+i

endfor

thisform.text1.value=s

19计算e的近似值

s=0

i=1

n=1

m=1

do while m>=0.000001

n=n*i

m=1/n

i=i+1

s=s+m

enddo

thisform.text1.value=s

20求出所有的水仙花数

for i=100 to 999

x1=int(i/100)

x2=int(mod(i,100)/10)

x3=mod(i,10)

if x1^3+x2^3+x3^3=i

thisform.label1.caption=thisform.label1.caption+str(i,5)

endif

endfor

22输入字符串逆序显示

x=alltrim(thisform.text1.value)

c=""

for i=len(x) to 1 step -1

c=c+substr(x,i,1)

endfor

thisform.label1.caption=c

23显示ASSIC字符中的数字字符串

a=alltrim(thisform.text1.value)

c=" "

for i=1 to len(a) step 1

b=substr(a,i,1)

if asc(b)>=asc("0") and asc(b)<=asc("9")

c=c+b

endif

endfor

thisform.label1.caption=c

24显示ASSIC字符中的大写字母串

a=alltrim(thisform.text1.value)

c=" "

for i=1 to len(a) step 1

b=substr(a,i,1)

if asc(b)> asc("A") and asc(b)<=asc("Z")

c=c+b

endif

endfor

thisform.label1.caption=c

25求圆面积,迎获得焦点即计算

Text2 gotfocus 事件

程序不变

26求圆面积,text1失去焦点,即输完字后敲回车即计算

Text1 valid事件或者lostfocus事件

27修改label1 的相应字体command group

do case

case this.value=1

thisform.label1.fontname="宋体"

case this.value=2

thisform.label1.fontname="黑体"

case this.value=3

thisform.label1.fontname="楷体"

case this.value=4

thisform.label1.fontname="隶书"

case this.value=5

thisform.release

Endcase

28

28

x=thisform.text1.value

y=thisform.text2.value

do case

case thisform.optiongroup1.value=1

z=x+y

case thisform.optiongroup1.value=2

z=x-y

case thisform.optiongroup1.value=3

z=x*y

case thisform.optiongroup1.value=4

z=x/y

endcase

thisform.text3.value=z

29list中输入*的直角三角形

y="*"

for i=1 to 5

thisform.list1.additem(y)

y=y+"*"

endfor

30列表框中显示斐波拉契数列

f1=1

f2=1

thisform.list1.addlistitem(" 1",1,1)

thisform.list1.addlistitem(" 1",1,2)

x=1 && x表示行号

y=3 && y表示列号

for i=3 to 20

f3=f1+f2

thisform.list1.addlistitem(str(f3,5),x,y)

f1=f2

f2=f3

y=y+1

if y=6

x=x+1 && x+1即行号加1,换行

y=1 && 换行后列号回1

endif

endfor

31 100150中第一个能被3整除的数找出来。 EXIT跳出当前循环

For n=100 to 150

if n%3=0

thisform.text1.value=n

exit

endif

Endfor

32用编辑框显1100的奇数

k=0

for i=1 to 100 step 2

k=k+1

thisform.edit1.value=thisform.edit1.value+str(i,5)

if k%8=0

thisform.edit1.value=thisform.edit1.value+ chr(13)

endif

Endfor

33 用编辑框输出大写字母表

n=0

for i=asc("A") to asc("Z")

thisform.edit1.value=thisform.edit1.value+ chr(i) +space(2)

n=n+1

if n%6=0

thisform.edit1.value=thisform.edit1.value+ chr(13)

endif

endfor

34查询图书表中包含程序二字的图书信息

select * from 图书 where 书名 like "%程序%" into cursor temp

thisform.grid1.recordsource="temp"

35查询图书表中图书的价格在2830之间的图书。

select * from 图书 where 价格 between 28 and 30 into cursor temp thisform.grid1.recordsource=temp "

第二类

select * from 图书 where 价格>=28 and 价格<=30 into cursor temp

thisform.grid1.recordsource="temp"

36按办证日期先后顺序显示读者表中的读者信息。

select * from 读者 order by 办证日期 into cursor temp

thisform.grid1.recordsource="temp "

37在借阅表中按读者编号从大到小的顺序,读者编号相同时按借阅日期的先后顺序显示读者编号、书号及借阅日期。

select 读者编号,书号,借阅日期 from 借阅 order by 读者编号 desc, 借阅日期 asc into cursor temp

thisform.grid1.recordsource="temp "

注: 通过ORDER BY子句可以实现查询结果的排序输出,允许按一列或多列排序。

格式:

ORDER BY <排序选项1>ASC|DESC][,< 排序选项2>ASC|DESC]…]

其中,ASC表示升序排序(缺省方式),DESC表示降序排序。

38显示图书表中数量最多的两种图书信息。

表单Form1Init事件代码如下:

select top 2 * from 图书 order by 数量 desc

into cursor temp

thisform.grid1.recordsource=temp "

注: 使用TOP <数值表达式> PERCENT]短语显示部分结果。注意:TOP短语要与ORDER BY短语同时使用才有效。

【例】显示价格最低的20%图书的信息。

SELECT * TOP 20 PERCENT FROM 图书 ORDER BY 价格

39计算图书表中图书的平均价格,保存在数组DJ中。

select avg(价格) from 图书 into array dj

thisform.label1.caption="图书的平均价格 :"+ str(dj(1),5,2)+""

注:使用INTO ARRAY <数组名>将查询结果存放到数组中。

40将图书表中最高单价和最低单价分别显示在文本框text1text2中。

SQL语句改为:

select max(价格)as 最高单价,min(价格)as 最低单价 from 图书 into array cj

thisform.text1.value=cj(1)

thisform.text2.value=cj(2)

41将图书表中最高单价和最低单价分别显示在文本框text1text2中。其SQL语句改为:

select max(价格) as 最高单价,min(价格) as

最低单价 from 图书 into array x

Thisform.label3.caption=str(x(1),4,1)

Thisform.label4.caption=str(x(2),4,1)

42

计算图书表中每个出版社的图书数量。

注: 通过GROUP BY子句可以实现分组查询。

格式:

GROUP BY <分组字段名1>,<分组字段名2>…]

HAVING <过滤条件>

其中,<分组字段名>可以是表的字段名、字段函数名或标识列的数值型表达式;[HAVING <过滤条件>]子句进一步限定分组的条件。

表单Form1Init事件代码如下:

select 出版社,sum(数量) as 数量 from 图书 group by 出版社

into cursor temp

thisform.grid1.recordsource=temp"

43在借阅表中统计每本图书的借阅次数。

Select 书号,count (*) as 借阅次数 from 借阅 group by 书号 into cursor temp

Thisform.grid1.recordsource=temp

44查询至少被借阅了2次的图书的书号及书名。

注,此方法可以运行

select 书号, 书名 from 图书 where 书号 in (select 书号 from 借阅 group by 书号 having count(*)>=2) into cursor lsb

thisform.grid1.recordsource="lsb"

方法2(运行故障,)select 图书.书号,书名 from 图书,借阅 ;

where 图书.书号=借阅.书号 group

by图书.书号 having count(*)>=2;

into cursor temp

thisform.grid1.recordsource=temp "

方法3 (运行故障)Select 图书.书号,书名 from 图书 inner join ;

借阅 on 图书.书号=借阅.书号;

group by 图书.书号;

having count(*)>=2;

into cursor temp

thisform.grid1.recordsource=temp "

45输入图书编号,查询借阅该图书的读者姓名、单位、联系电话。

方法1:

“查询”按钮的Click事件代码如下:

bh=alltrim(thisform.text1.value)

select

读者姓名,单位,联系电话;

from 读者,借阅

where 读者.读者编号=借阅.读者编号;

and 书号=bh ;

into cursor temp

thisform.grid1.recordsource= temp "

方法2:

“查询”按钮的Click事件代码如下:

bh=alltrim(thisform.text1.value)

select 读者姓名,单位,联系电话 from 读者;

inner join 借阅 on 读者.读者编号=

借阅.读者编号 where 书号=bh ;

into cursor temp

thisform.grid1.recordsource=temp "

方法3:

“查询”按钮的Click事件代码如下:

bh=alltrim(thisform.text1.value)

select 读者姓名,单位,联系电话 from 读者 where 读者编号 in (select 读者编号 from 借阅 where 书号=bh) into cursor temp

thisform.grid1.recordsource=temp "

46输入读者编号,查询该读者的姓名、单位、借阅的图书的书名及借阅日期。

bh=alltrim(thisform.text1.value)

select 读者姓名,单位,书名,借阅日期 from 读者,借阅, 图书 where 读者.读者编号= 借阅.读者编号 and 借阅.书号= 图书.书号 and 读者.读者编号=bh into cursor temp

thisform.grid1.recordsource="temp"

51

Edit 编辑框的interactivechange代码

zy=thisform.combo1.value

select 学号,姓名,成绩 from xs,cj where 专业=zy into array ca

select avg(成绩),count(成绩< 60 ) from ca into array cb

thisform.texy1.value=cb(1)

thisform.text2.value=cb(2)

退出

Quit

52

本文来源:https://www.2haoxitong.net/k/doc/3c99603e33687e21ae45a955.html

《带星号的程序代码总结.doc》
将本文的Word文档下载到电脑,方便收藏和打印
推荐度:
点击下载文档

文档为doc格式