第9章習(xí)題
單選題
1.B 2.D 3.D
4.B 5. A 6. A
編程及上機(jī)調(diào)試
1. 程序代碼如下:
Private Sub Form_load()
Dim x(3) As Single, y As Single
On Error GoTo errln '以后出錯(cuò)時(shí)轉(zhuǎn)移到errln
y = 2 / 0 '產(chǎn)生"除數(shù)為0"的錯(cuò)誤
x(4) = 1 '產(chǎn)生"下標(biāo)越界"的錯(cuò)誤
MsgBox ("終止程序的運(yùn)行")
Unload Me '卸載窗體
End
errln: '標(biāo)號(hào)
Select Case Err.Number
Case 11 '"除數(shù)為0"的錯(cuò)誤碼為11
MsgBox ("除數(shù)為0(錯(cuò)誤碼為11),跳過(guò)該錯(cuò)誤")
Resume Next '返回
Case 9 '"下標(biāo)越界"的錯(cuò)誤碼為9
MsgBox ("下標(biāo)越界(錯(cuò)誤碼為9),跳過(guò)該錯(cuò)誤")
Resume Next '返回
Case Else '其他錯(cuò)誤處理
MsgBox ("錯(cuò)誤發(fā)生在" & Err.Source _
& ", 代碼為" & Err.Number _
& ", 即" & Err.Description)
End Select
End Sub
2.改正后的程序代碼如下:
Private Sub Form_Load()
Show
For i = 1 To 11
Print Tab(20 - i);
For j = 1 To 2 * i - 1
If j <= i Then
k = j
Else
k = 2 * i - j
End If
If k > 9 Then k = k + 7
Print Chr(k + 48);
Next j
Next i
End Sub
3.(1) n = n + 1 (2) d(1, j) = d(3, j) (3) d(i, 2) = d(i, 4)
(4) i = j Or i + j = 5 (5) d(i, j) = d(i, j) + 1
(6) n = 0 (7) Text1.Text