1、编程题1 编写程序在窗体上输出如下图形。Private sub form_click()Dim I,j,k as integerForm1.fontsize=20PrintFor i=1 to 7Print tab(i);For j=1 to 14-(2*i-1)Print “*”;Next jPrint “”;For k=1 to 2*i-1?”$”;Next kPrintNext iEnd sub2 设计一个窗体,输入一个三位整数,将它反向输出。例如输入 246,输出642。Private sub command1_click()Dim s,x,y,z,k as integerS=val(
2、text1.text)X=s100Y=s10 mod 10Z=s mod 10K=z*100+y*10+x 或 k=zmax;”分”Print “最低分是”;min; ”分”Print “平均分是”;aver; ”分”End sub9求一个 33矩阵对角线元素之和。Private sub command1_click()Dim a(1to3,1to3)as integerDim I,j ,sum as integerSum=0for i=1 to 3for j=1 to 3 a(i,j)=inputbox(“输入数据”)next jnext ifor i=1 to 3sum=sum+a(i,i
3、)next iprint sum10今有 n 个数,请编程将这些数按由大到小的顺序排列“降序排列” (交换排序)。Dim a(1 to 10)as integerPrivate sub command1_click()Form_loadEnd subPrivate sub command2_click()P=”For i=1 to 9For j=i+1 to 10If a(i)0 and b0 and c0 and (a+b)c and (a+c)b and (b+c)a thenL=a+b+cS=0.5*lArea=sqr(s*(s-a)*(s-b)*(s-c)ElseMsgbox a K=
4、k+1End ifIf k mod 10=0 then printNext iEnd sub15编制随机整数 Functio过程,输出 30个 1100之内的随机数。Private Sub Command1_Click()Dim a(1to30)As IntegerForm1 Fontsize = 20For i = 1to30A(i) = sjPrint a(i);If I mod 5=0 then print chr(13)Next iEnd subPublic function sj()as integerRandomizeSj=int(rnd*99+1)endfunction16编写程
5、序,求出 s=1+(1+3)+(1+3+5)+ +(1+3+5+2n-1)的值。Private Sub form1_Click()N=inputbox(“请输入 N的值”)K=0 s=0Fori=ltonK=k+(2*I-1)S=s+kNextiPrint“1+(1+3)+(1+3+2n-1)=”,End Sub17用随机函数产生 10个在 1100范围内的随机数,找出最大数和最小数。Dim a(1to 10)as integerPrivate Sub Command1_Click()Dim max as integer,min as integerMin=100:max=0For i=1 t
6、o 100If a(i)max then max=a(i)If a(i)”thenText1.text=file1.path&”& file1.filenameElseText1.text=file1.path&file1.filenameEndifEnd subPrivate sub command1_clik()Dim int1Int1=sell(text1.text,vbnormalfocus)End sub19设计一个倒计时器,当在文本框中输入一个分钟数,单击命令按钮就开始倒计时,在倒计时结束时,出现信息框“时间到!”的提示。Dim t ,s as integerPrivate Sub
7、 Command1_Click()T=val(text1.text)S=t*60Timer1.enabled=trueEnd subPrivate Sub Command2_Click()End End subPrivate Sub timer1_timer()Label3.caption=sIf s=0 thenX=msgbox(“时间到!”,”提示”)Timer1.enabled=falseEndiS=s-1End sub20编写程序,要求输入两个实数,再选择“”、“”、“”、“”四个按钮之一,根据所选择的运算符计算并输出结果。要求: 四个运算符号用选项按钮组实现。 用两个文本框输入实数,
8、计算结果显示在标签中。 设计一个命令按钮(计算),编写命令按钮的单击事件。Dim x,y,s,c ,j,k as singlePrivate Sub Command1_Click()Label6.caption=sEnd subPrivate Sub option1_click(index as integer)X=val(text1.text)Y=val(text2.text)Select case indexCase 0S=x+yLabel4.caption=”+”Label6.caption=”Case 1S=x-yLabel4.caption=”-”Label6.caption=”Case 2S=x*yLabel4.caption=”*”Label6.caption=”Case 3S=x/yLabel4.caption=”Label6.caption=”End selectEnd sub