当前位置:文档之家› VB考试试卷及答案一

VB考试试卷及答案一

VB考试试卷及答案一
VB考试试卷及答案一

Visual Basic程序设计基础

试题一(每小题2分,共10分)

阅读下列程序说明和程序,在每小题提供的若干可选答案中,挑选一个正确答案。

【程序说明】

过程JiSuan用于计算e = 1 + 1/1! + 1/2! + 1/3! + …+1/n!的值,直至末项小于0.00001(不包含小于0.00001的项),并用消息框显示结果。

【程序】

Option Explicit

Private Sub JiSuan()

Dim e As single, (1) , i As long

e = 1: t = 1: (2)

(3)

i = i + 1: e = e + t: (4)

Loop

(5)

End Sub

【供选择的答案】

(1)A、t As String B、Dim t As String C、Dim t As Single D、t As Single

(2)A、i = 1 B、i = 2 C、i = 0 D、i = 3

(3)A、While t >= 0.00001 B、Do While t >= 0.00001

C、While e >= 0.00001

D、Do While e >= 0.00001

(4)A、t = t * i B、t = 1/(i * t) C、t = t / i D、t = 1 / i

(5)A、MsgBox "近似值为:" + t

B、MsgBox "近似值为:" & t

C、MsgBox "近似值为:" + e

D、MsgBox "近似值为:" & e

试题二(每小题2分,共8分)

阅读下列程序说明和程序,在每小题提供的若干可选答案中,挑选一个正确答案。

【程序说明】

程序界面如下图所示,程序运行时要求有以下功能:

1.单击“加粗”复选框(Check1),若复选框被选中,则设置标签(Label1)上显示的文

字为加粗,否则设置为不加粗。

2.单击“选择颜色”按钮(Command1)将显示“颜色”对话框,若单选按钮“前景色”

(Option1)被选中,则设置Label1的前景色为用户选择的颜色,否则设置Label1

的背景色为用户选择的颜色。通用对话框控件名称为CommonDialog1。

【程序】

Private Sub Check1_Click()

Label1.FontBold = False

If (6) Then Label1.FontBold = True

End Sub

Private Sub Command1_Click()

Dim c As Long : (7) : c = (8)

If (9) Then Label1.ForeColor = c Else Label1.BackColor = c

End Sub

【供选择的答案】

(6)A、Check1.Value = True B、Check1.Value = False

C、Check1.Value = 1

D、Check1.Value = 0

(7)A、CommonDialog1.ShowOpen B、CommonDialog1.ShowColor

C、CommonDialog1.ShowSave

D、CommonDialog1.Action = 1

(8)A、CommonDialog1.ForeColor B、CommonDialog1.FontColor

C、CommonDialog1.BackColor

D、CommonDialog1.Color

(9)A、Option1.Value B、Option1.Value = 1

C、Option1.Value = false

D、Option1.Value = 0

试题三(每小题2分,共10分)

阅读下列程序说明和程序,在每小题提供的若干可选答案中,挑选一个正确答案。

【程序说明】

程序界面如上面两图所示,程序运行时要求有以下功能:

1.当用户单击“增加”按钮(Command1),若文本框(Text1)中的内容不为空,则将文

本框中的内容添加到列表框末尾,并自动将文本框中的内容选中。

2.当用户单击“删除”按钮(Command2),若列表框中没有表项被选中,则用消息框

提示“没有选择表项”,否则删除被选中的表项。

3.文本框仅允许输入数字字符与退格字符(ASCII码值为8)。

【程序】

Private Sub Command1_Click()

Dim s As String, t As String

s = Text1.Text

If s = "" Then Exit Sub

(10) : Text1.SetFocus

Text1.SelStart = 0: (11)

End Sub

Private Sub Command2_Click()

If List1.ListIndex = -1 Then MsgBox "没有选择表项" Else (12)

End Sub

Private Sub Text1_ (13)

If (14) Then KeyAscii = 0

End Sub

【供选择的答案】

(10)A、List1.AddItem s,List1.ListCount B、List1.AddItem s, 0

C、List1.AddItem s, List1.ListCount - 1

D、List1.AddItem s;0

(11)A、Text1.SelLength = Len(Text1.Text)

B、Text1.SelLength = Len(Text1.SelText)

C、Text1.SelText = Text1.Text

D、Text1.Text = Text1.SelText

(12)A、List1.RemoveItem List1.Text

B、List1.RemoveItem List1.ListCount

C、List1.RemoveItem List1.ListIndex –1

D、List1.RemoveItem List1.ListIndex

(13)A、KeyPress(KeyAscii As Integer) B、Change(KeyAscii As Integer)

C、Change

D、KeyPress(KeyAscii As String)(14)A、(KeyAscii > Asc("9") or KeyAscii < Asc("0")) and KeyAscii = 8

B、KeyAscii > Asc("9") And KeyAscii < Asc("0") Or KeyAscii = 8

C、(KeyAscii > Asc("9") or KeyAscii < Asc("0")) And KeyAscii <> 8

D、KeyAscii > Asc("9") and KeyAscii < Asc("0") and KeyAscii <> 8

试题四(每小题2分,共14分)

阅读下列程序说明和程序,在每小题提供的若干可选答案中,挑选一个正确答案。

【程序说明】

程序界面如下图所示,程序运行时要求有以下功能:

1.单击“排序”按钮(Command1),将左边文本框(Text1)中的字符按从小到大的顺序

排列,并显示到右边文本框(Text2)中。

【程序】

Private Sub Command1_Click()

Dim s As String, c() As String, slen As Integer

Dim i As Integer, j As Integer, p As Integer

s = Trim(Text1.Text)

slen = _ (15) : _ (16)

For i = 1 To slen

c(i) = _ (17)

Next i

For i = 1 To slen - 1

p = i

For j = _ (18)

If _ (19) Then p = j

Next j

If p <> i Then _ (20)

Text2.Text = Text2.Text + c(i)

Next i

Text2.Text = _ (21)

End Sub

Private Sub swap(a As String, b As String)

Dim t As String: t = a: a = b: b = t

End Sub

【供选择的答案】

(15)A、Len(s) B、Val(s) C、Asc(s) D、Length(s)

(16)A、ReDim c() B、Dim c() as string

C、ReDim c(1 to slen)

D、Dim c(1 to slen)

(17)A、Mid(s,i) B、Left(s,i) C、Mid(s,i,1) D、Asc(Mid(s,i,1))

(18)A、1 to slen-i B、i+1 to slen C、i to slen-1 D、1 to slen

(19)A、c(p)>c(j) B、c(p)c(j)

(20)A、swap c(p),c(i) B、Call swap c(p),c(i)

C、swap c(p),c(j)

D、Call swap(c(p),c(j))

(21)A、Text2.Text + c(j) B、Text2.Text + c(i)

C、c(j)

D、c(i)

试题五(每小题2分,共8分)

阅读下列程序,在每小题提供的若干可选答案中,挑选一个正确答案。

【程序】

Dim a As Byte

Private Sub Form_click()

'Dim a As Byte '(1)

a = a + 2

Call aa(a) '(2)

Print a;

End Sub

Sub aa(b As Byte) '(3)

b = a + 2

End Sub

【供选择的答案】

(22)单击窗体两次后,窗体上显示的内容是什么?

A、0 0

B、2 2

C、2 4

D、4 8

(23)其它代码不变,仅将程序中的语句(1)前面的单引号“’”删除,单击窗体两次后,窗体上显示的内容是什么?

A、0 0

B、2 2

C、2 4

D、4 8

(24)其它代码不变,仅将程序中的语句(2)改为call aa(a+2),单击窗体两次后,窗体上显示的内容是什么?

A、0 0

B、2 2

C、2 4

D、4 8

(25)其它代码不变,仅将程序中的语句(3)改成sub aa(byval b as byte),单击窗体两次后,窗体上显示的内容是什么?

A、0 0

B、2 2

C、2 4

D、4 8

试题六(每小题2分,共12分)

阅读下列程序说明和程序,在每小题提供的若干可选答案中,挑选一个正确答案。

【程序说明】

程序界面如下图所示,程序运行时要求有以下功能:

1.单击影像框(Image1),定时器(timer1)开始运行;再次单击影像框,定时器停止

运行。

2.定时器运行时,每隔一定时间更换影像框中的图片:第1次显示“c:\pic1.bmp”

的图片,第2次显示“c:\pic2.bmp”的图片,第3次显示“c:\pic3.bmp”的图片,第4次又显示“c:\pic1.bmp”的图片……依次类推。

3.滚动条(HScroll1)用于控制定时器Timer1的Timer事件时间间隔。

【程序】

Dim i As Byte

Private Sub Form_Load()

HScroll1.Min = 1000: HScroll1.Max = 10000: HScroll1.SmallChange = 1000

https://www.doczj.com/doc/bd18928294.html,rgeChange = 3000: HScroll1.Value = 1000 : i = 1

Timer1.Enabled = False: Timer1.Interval = HScroll1.Value

End Sub

Private Sub HScroll1_Change()

_ (26)

End Sub

Private Sub Image1_Click()

_ (27)

End Sub

Private Sub Timer1_Timer()

Dim fn As String

fn = "c:\pic" +_ (28) + ".bmp"

_ (29)

if i < 3 then i = i + 1 else _ (30)

End Sub

【供选择的答案】

(26)A、Timer1.Interval = HScroll1.Value B、Timer1.Index= HScroll1.Value

C、HScroll1.Value = Timer1.Interval

D、HScroll1.Value= Timer1.Index

(27)A、Timer1.Enabled = Not Timer1.Enabled B、Timer1.Enabled = True

C、Timer1.Interval = 0

D、Timer1.Enabled = False

(28)A、Trim(Chr(i)) B、Str(i) C、Trim(Str(i)) D、Chr(i)

(29)A、Image1.Image = LoadPicture(fn) B、Image1.Image = fn

C、Image1.Picture = LoadPicture(fn)

D、Image1.Picture = fn

(30)A、i = i - 2 B、i = 2 C、i = 0 D、i = i - 1

(31)程序启动后,单击滚动条右边箭头一次,再单击滑块与右边箭头空白处一次后,滚动条的Value属性的值为:

A、3000

B、4000

C、5000

D、6000

试题七(每小题2分,共8分)

阅读下列程序说明和程序,在每小题提供的若干可选答案中,挑选一个正确答案。

【程序说明】

程序界面如下图所示,程序运行时要求有以下功能:

1.在窗体的Load事件过程中,设置图片框p1中的内部坐标系如下:图片框左、右

边线在其内部坐标系中的横坐标分别为0、200,上、下边线在其内部坐标系中的

纵坐标分别为50、-50。

2.单击“中心线”按钮(Command1),在图片框的水平和垂直的中心位置画两条直

线,效果如左下图所示。

3.单击“画图”按钮(Command2),在图片框上画5个大小相等并水平相接的圆,

效果如右下图所示。

【程序】

Private Sub Form_Load()

_ (32)

End Sub

Private Sub Command1_Click()

_ (33)

P1.Line (100, 50)-(100, -50)

End Sub

Private Sub Command2_Click()

Dim r As Integer

r = _ (34) For i = _ (35)

p1.Circle (r * i, 0), r, vbBlue Next i End Sub

【供选择的答案】 (32) A 、p1.Scale (-50,0)-(50,200) B 、p1.Scale (0,-50)-(200,50)

C 、p1.Scale (50,0)-( -50,200)

D 、p1.Scale (0,50)-(200,-50)

(33) A 、p1.Line (200,0)-(0,0) B 、p1.Line –(200,0)

C 、p1.Line (0,-50)-(200,-50)

D 、p1.Line (0,50)-(200,50)

(34) A 、p1.ScaleWidth / 5 B 、p1.Width / 5

C 、p1.ScaleWidth / 10

D 、p1.Width / 10

(35) A 、9 to 1 Step -1 B 、1 to 9 Step 2

C 、1 to 5

D 、5 to 1 Step -1

试题八(8分)

编程,用Inputbox 函数输入x ,根据下面公式计算y 值,并在窗体上显示y 值。代码写在窗体的Click 事件过程中。

y = ???????<<>+0

≤0103≤≤1332

x x x x x x x 当当当当

试题九(8分)

编写一个自定义函数CalcAVG ,计算Single 类型一维数组所有元素的平均值。

试题十(14分)

界面设计、运行时状态如下图所示,按照下列要求定义各事件过程:

1.为窗体的Load事件编写代码,使得文件列表框(File1)仅显示文本文件(*.txt)

2.实现驱动器列表框(Drive1)和目录列表框(Dir1),及文件列表框(File1)的联动。

3.单击文件列表框中某一文件,将被选中文件的内容原样显示在文本框(Text1)中。

4.单击“退出”按钮(Command1),结束程序运行。

参考答案

试题一:DABCD

试题二:CBDA

试题三:AADAC

试题四:ACCBAAB

试题五:DBCC

试题六:AACCAC

试题七:DACB

试题八:(8)

Private Sub Form_click()

Dim x As Single, y As Single ’1分

x = Val(InputBox("x=")) ’1分

Select Case x ’5分

Case Is > 3

y = x + 3

Case Is >= 1

y = x * x

Case Is > 0

y = Sqr(x)

Case Else

y = 0

End Select

Print y ’1分

End Sub

试题九:(8)

'函数头定义2分,其中数组参数定义1

分,返回值类型1分

Function CalcAVG(a() As Single, n As

Integer) As Single

Dim h As Single, i As Integer '变量定

义1分

For i = 1 To n '循环2分

h = h + a(i) '累加1分

Next i

CalcAVG = h / n '函数赋值1分,求平

均值1分

End Function

试题十:(14)

Private Sub Command1_Click()

End '1

End Sub

Private Sub Form_Load()

File1.Pattern = "*.txt" '1分

End Sub

Private Sub Dir1_Change()

File1.Path = Dir1.Path '1分End Sub

Private Sub Drive1_Change()

Dir1.Path = Drive1.Drive '1分End Sub

Private Sub File1_Click()

Dim fs As String, s As String

'获取完整文件名3分

If Right(File1.Path, 1) = "\" Then

fs = File1.Path + File1.FileName Else

fs = File1.Path + "\" + File1.FileName

End If

Open fs For Input As #1 '打开文件2分

While Not EOF(1) '循环2分

Line Input #1, s '读取行1分

'累加1分

Text1.Text = Text1.Text + s + Chr(13) + Chr(10)

Wend

Close #1 '打开文件1分

End Sub

相关主题
文本预览
相关文档 最新文档