1、Visual Basic程序设计基础试题一(每小题2分,共10分)阅读下列程序说明和程序,在每小题提供的若干可选答案中,挑选一个正确答案。【程序说明】过程JiSuan用于计算e = 1 + 1/1! + 1/2! + 1/3! + +1/n!的值,直至末项小于0.00001(不包含小于0.00001的项),并用消息框显示结果。【程序】Option ExplicitPrivate 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 Su
2、b【供选择的答案】(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.00001C、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 近似值为: + tB、MsgBox 近似值为: & tC、MsgB
3、ox 近似值为: + eD、MsgBox 近似值为: & e试题二(每小题2分,共8分)阅读下列程序说明和程序,在每小题提供的若干可选答案中,挑选一个正确答案。【程序说明】程序界面如下图所示,程序运行时要求有以下功能:1. 单击“加粗”复选框(Check1),若复选框被选中,则设置标签(Label1)上显示的文字为加粗,否则设置为不加粗。2. 单击“选择颜色”按钮(Command1)将显示“颜色”对话框,若单选按钮“前景色”(Option1)被选中,则设置Label1的前景色为用户选择的颜色,否则设置Label1的背景色为用户选择的颜色。通用对话框控件名称为CommonDialog1。【程序】
4、Private Sub Check1_Click() Label1.FontBold = False If (6) Then Label1.FontBold = TrueEnd SubPrivate Sub Command1_Click() Dim c As Long : (7) : c = (8) If (9) Then Label1.ForeColor = c Else Label1.BackColor = cEnd Sub【供选择的答案】(6) A、Check1.Value = True B、Check1.Value = FalseC、Check1.Value = 1 D、Check1.
5、Value = 0(7) A、CommonDialog1.ShowOpen B、CommonDialog1.ShowColorC、CommonDialog1.ShowSave D、CommonDialog1.Action = 1(8) A、CommonDialog1.ForeColor B、CommonDialog1.FontColorC、CommonDialog1.BackColor D、CommonDialog1.Color(9) A、Option1.Value B、Option1.Value = 1C、Option1.Value = false D、Option1.Value = 0试题
6、三(每小题2分,共10分)阅读下列程序说明和程序,在每小题提供的若干可选答案中,挑选一个正确答案。【程序说明】 程序界面如上面两图所示,程序运行时要求有以下功能:1. 当用户单击“增加”按钮(Command1),若文本框(Text1)中的内容不为空,则将文本框中的内容添加到列表框末尾,并自动将文本框中的内容选中。2. 当用户单击“删除”按钮(Command2),若列表框中没有表项被选中,则用消息框提示“没有选择表项”,否则删除被选中的表项。3. 文本框仅允许输入数字字符与退格字符(ASCII码值为8)。【程序】Private Sub Command1_Click() Dim s As Stri
7、ng, t As Strings = Text1.Text If s = Then Exit Sub (10) : Text1.SetFocus Text1.SelStart = 0: (11) End SubPrivate Sub Command2_Click() If List1.ListIndex = -1 Then MsgBox 没有选择表项 Else (12) End SubPrivate Sub Text1_ (13) If (14) Then KeyAscii = 0End Sub【供选择的答案】(10) A、List1.AddItem s,List1.ListCount B、L
8、ist1.AddItem s, 0C、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.TextD、Text1.Text = Text1.SelText(12) A、List1.RemoveItem List1.TextB、List1.RemoveItem List1.ListCountC、List1.RemoveItem List
9、1.ListIndex 1D、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(9) And KeyAscii Asc(9) or KeyAscii Asc(0) And KeyAscii 8D、KeyAscii Asc(9) and KeyAscii Asc(0) and KeyAscii 8
10、试题四(每小题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
11、= _ (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 SubPrivate Sub swap(a As String, b As String) Dim t As String: t = a: a = b: b = tEnd Sub【供
12、选择的答案】(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) C、c(i)c(j)(20) A、swap c(p),c(i) B
13、、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 BytePrivate Sub Form_click() Dim a As Byte (1) a = a + 2 Call aa(a) (2) Print a;End SubSub aa(b As Byte) (3) b = a + 2End Sub【供
14、选择的答案】(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
15、、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
16、 As BytePrivate Sub Form_Load() HScroll1.Min = 1000: HScroll1.Max = 10000: HScroll1.SmallChange = 1000 HScroll1.LargeChange = 3000: HScroll1.Value = 1000 : i = 1 Timer1.Enabled = False: Timer1.Interval = HScroll1.ValueEnd SubPrivate Sub HScroll1_Change() _ (26) End SubPrivate Sub Image1_Click() _ (2
17、7) End SubPrivate Sub Timer1_Timer() Dim fn As String fn = c:pic +_ (28) + .bmp _ (29) if i 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 A
18、s 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 SubPrivate Sub Form_Load() File1.Pattern = *.txt 1分End SubPrivate Sub Dir1_Change() File1.Path = Dir1.Path 1分End SubPrivate Sub Drive1_Change() Dir1.P
19、ath = Drive1.Drive 1分End SubPrivate 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