VB复习题库(7)

2019-04-02 13:02

n=len(a$) For i=1 to n

Dec=dec*2+ (a$,i,1) Next i Print dec End sub

程序功能为:单击命令按钮,将产生一个输入对话框,此时如果在对话框中输入一个二进制数,并单击确认按钮,则把该二进制数转换为等值的十进制数,这个程序不完整,应在“ ”处输入的内容是( D ) A.right B.left C.val D.mid 填空题、 1、有如下程序: Private sub form--click() Dim i as integer,n as integer For i= 1 to 20 I=i+4 n=n+i

If i>10 then exit for Next Print n End sub

程序运行后,单击窗体,则输出结果是 30 2、运行如下程序: Private sub command1-click() Dim a(5,5) as integer For i=1 to 5 For j=1 to 4 a(i,j)=i*2+j

If a(i , j )/7=a( i , j )\\7 then n=n+1 End if Next j Next i Print n End sub

n的值是 3 。

3、窗体上有一个名称为command1的命令按钮,事件过程如下: Private sub command1-click() Dim x%,y%,z%

X=inputbox(\请输入第一个整数\Y=inputbox(\请输入第二个整数\)

。 Do until x=y

If x>y then x=x-y else y=y-x Loop Print x End sub

运行程序,单击命令按钮,并输入2个整数169和39,则在窗体上显示的内容为 13 。 程序填空

1、编写英文打字练习程序,要求如下; (1)在一个文本框内随机产生30个字母的范文。

(2)当焦点进入零一个文本框时开始计时,按产生的范文练习打字。

(3)当满30个字母结束计时,禁止向文本框输入内容。显示打字时间和打字准确率。 Option explicit Dim i as date

Private sub command1-click() '产生30个字母的范文 Randomize

Dim i as integer,a as string Text1=\For i =1 to 30

a=chr$(int(rnd*26)+65) '随机产生大写字母

Text1= text1+a '产生的字母连入范文框 Next i End sub

--------------------------------------------------------------------------------------------------------------------- Private sub command2-click() End End sub

---------------------------------------------------------------------------------------------------------------------- Private sub text2-gotfocus()

T = time '键入文本框获得焦点,开始计时 End sub

--------------------------------------------------------------------------------------------------------------------- Private sub text2-keypress (keyascii as integer) Dim t2 as integer,y as integer, n as integer,i as integer If len(text2)=30 then '键入满30个字符 T2=datediff(\ '计算速度 Text4=t2&\秒\ ’显示速度 Text2.locked=True '不允许再次修改 y=0:n=0

For i=1 to 30 ‘比较正确率 If mid(text1,i,1)=mid(text2,i,1) then y= y=1 Else

n= n+1

End if Next i y=y/(y+n)*100

Text3=y&\ '显示正确率 End if End sub

2、编写一个程序,该程序的功能是:利用随机函数rnd生成10个10~~99之间的整数,并计算其中的素数的个数。

Private sub command1--click() Randomize

Dim i as integer,j as integer,n as integer,n1 as integer,st as string For i=1 to 10

n=int( 90*rnd+10) St=st&n&\For j=2 to sqr(n)

If n mod j =0 then exit for Next j

If j> sqr(n) then n1=n1+1 End if Next i Text1.text=st Text2.text=n1 End sub

------------------------------------------------------------------------------------------------------------------- Private sub command2-click() Text1.text=\Text2.text=\Text1.setfocus End sub

-------------------------------------------------------------------------------------------------------------------- Private sub command3-click() End End sub

2、编写一个把十进制整数转化成二进制整数的程序 Private sub command1-click()

Dim n as integer,st as string ,p as string*1 Do

P= trim(str(n mod 2)) St=p&st

n= n\\2

Loop while n>0 Text2.text=st End sub

------------------------------------------------------------------------------------------------------- Private sub command2-click() Text1.text=\Text2.text=\Text1.setfocus End sub

--------------------------------------------------------------------------------------------------- Private sub command3-click() End End sub

3、编写一个程序,改程序的功能是:能够将输入的字符串逆序输出。 【text1:输入字符串;text2:字符串逆序;text3:字符串长度】 Private sub command1-click() Dim i as integer,n as integer,s as string n=len(text1.text) For i=n to 1 step -1

S=s & mid( text1.text , i , 1 ) Next i Text2.text=s Text3.text=len(s) End sub

-------------------------------------------------------------------------------------------------- Private sub command2-click() Text1.text=\Text2.text=\Text3.text=\End sub

-------------------------------------------------------------------------------------------------- Private sub command3-click() End end sub

4、编写一个程序,该程序的功能是:输入任意一个正整数,若该数不是素数,则找出一个大于它的最小素数。

Private sub command1-click() Dim n as integer,i as integer n=val(text1.text)

Label2.caption=\大于\最小素数为:\For i = 2 to sqr(n)

If n mod i =0 then M=n

Do while flag=true M=m+1

For j= 2 to sqr(m)

If m mod j = 0 then exit for Next j

If j > sqr(m) then flag =false Text2.text=m Loop Exit for End if Next i

If i > sqr(n) then Msgbox n & \是素数\Text1.text=\Text2.text=\Text1.setfocus End if end sub

------------------------------------------------------------------------------------------------------ Private sub command2-click() Text1.text=\Text2.text=\Text1.setfocus End sub

-------------------------------------------------------------------------------------------------- Private sub command3-click() End end sub 实验九

一、对动态数组的生成、排序、插入元素和删除重复元素操作 。 Option Explicit Option Base 1 Dim a() As Integer

'利用随机函数给动态数组赋值

------------------------------------------------------------------------------------------------------------------- Private Sub Cmd_shengcheng_Click() Dim i As Integer ReDim a(10) Randomize Picture1.Cls

Picture1.Print \初始序列为:\ '**********FILL**********

___for i= 1 to 10___________________________

a(i) = Int(Rnd * 90 + 0) '利用随机函数产生数组元素的值 Picture1.Print a(i);


VB复习题库(7).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:xx风电集团防止人身伤亡事故专项措施-终稿

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: