2012VB练习题 下载本文

2012VB理论练习题

(1) Private Sub Form_Load() (2) End Sub

Private Sub Command1_Click() Text1.Text = \End Sub

Private Sub Command2_Click() If n < 0 Then n = -n: Text1.Text = \ While n <> 0

Text1.Text = (3) (4) Wend End Sub

【供选择的答案】

(1) A、Dim n As Byte B、Dim n As Integer C、Dim n As String D、Public n As Byte (2) A、Text1.Locked = True B、Text1.Locked = False C、Text1.Visible = True (3) A、n/10 & Text1.Text C、Text1.Text & n/10 (4) A、n = n \\ 10

D、Text1.Visible = False B、n Mod 10 & Text1.Text

D、Text1.Text & n Mod 10

B、n = n / 10

C、n = n Mod 10 D、n = n - 10

试题3

【程序】

Private Sub Command1_Click()

Dim a As Integer, b As Integer, x As Long, i As Integer On Error GoTo qq a = InputBox(\ b = InputBox(\ x = a

While Not (a Mod x = 0 And b Mod x = 0) x = x - 1 Wend Print x Exit Sub

qq: MsgBox \请重输\ Exit Sub

13

End Sub

【供选择的答案】

(1)单击Command1后,依次输入8、6后,显示: A、2 B、24 C、14 D、1 (2)单击Command1后,依次输入28、16后,显示: A、44 B、1 C、112 D、4 (3)单击Command1后,依次输入3、5后,显示:

A、15 B、1 C、8 D、125 (4)单击Command1后,依次输入4、32987后,显示: A、空白 B、1 C、0 D、请重输

试题4

【程序】 Dim m As Integer

Private Sub Command1_Click()

Dim a As Integer, i As Integer, f As Integer a = InputBox(\ f = 1: i = 2 Do While i <= a / 2

If a Mod i = 0 Then f = f + i i = i + 1 m = m + 1 Loop

Form1.Cls: Print f End Sub

【供选择的答案】

(1) 运行时第1次单击Command1输入7后,窗体上的显示结果为: A、1 B、3 C、5 D、7

(2) 运行时第2次单击Command1输入8后,窗体上的显示结果为: A、2 A、3

B、7 C、8 D、6 B、5 C、7 D、4

(3) 运行时第3次单击Command1输入9后,窗体上的显示结果为:

(4) 运行时3次单击Command1、并依次输入7、8、9后,变量m的当前值为: A、6 B、7 C、8 D、3

试题5

【程序】

Private Sub Form_click()

Dim n As Integer, i As Integer, k As Integer, j As Integer

14

2012VB理论练习题

Do

n = InputBox(\请输入1个1至9之间的整数\ Loop Until 0 < n And n < 10 k = 10: j = 1 For i = 1 To n

Print Space(k); String(j, Trim(Str(i))) If i <= n / 2 Then k = k - 1: j = j + 2 Else

k = k + 1: j = j - 2 End If Next i

End Sub

(1) 若运行时输入n值为2,窗体上的显示结果为: A、 1

B、 1 C、 1 D、 2

121 222 123 121 (2) 若运行时输入n值为3,窗体上的显示结果为: A、 1

B、 1 C、 1 D、 1

222 123 12 222 33333 12321 123 3 (3) 若运行时输入n值为4,窗体上的显示结果为: A、 1

B、 1 C、 1 D、 1

222 222 123 222 3 33333 12345 33333 444 444 1234567 4444444

试题17

【程序】

Private Sub Text1_KeyPress(K As Integer) If K < Asc(\ K = 0 Else

Label1.Caption = Chr(K) + Label1.Caption End If End Sub

【供选择的答案】

(1) Text1获得输入焦点后,依次按数字键1、3、5,Label1显示: A、135 B、531 C、9

D、5

(2) Text1获得输入焦点后,依次按数字键2、7、9,Label1显示:

15

A、972 B、279 C、297 A、-532

B、-235 C、532

D、18 D、235 D、521

(3) Text1获得输入焦点后,依次按 -、2、3、5键,Label1显示: (4) Text1获得输入焦点后,依次按 1、2、a、5键,Label1显示: A、空白 B、12a5 C、5a21

试题18

【程序说明】单击Command1后计算a?x+b?x+c的值并显示,界面设计以及运行时的显示分别如下图左、图右所示。要求在文本框中不可输入英文字母。

2

【程序】

Private Sub Command1_Click()

Dim a As Single, b As Single, c As Single, x As Single, y As Single a = Text1(0).Text: b = Text1(1).Text c = Text1(2).Text: x = Text1(3).Text y = a * x * x + b * x + c Label3.Caption = y End Sub

Private Sub Text1_ (1) (Index As Integer, (2) ) Select Case (3) Case \ K = 0

Case (4) K = 0 End Select End Sub

【供选择的答案】 (1) A、keyPress

B、change C、keyDown D、keyup B、Value C、Text() D、k As Integer B、Chr(K) C、Asc(K) D、Asc(KeyAscii)

C、\

D、'a'...'z'

(2) A、keyAscii As Integer

(3) A、Chr(KeyAscii)

(4) A、a To z B、'a' To 'z'

试题19

【程序】

Private Sub Form_Load()

16