第4章習(xí)題
一、單選題
1.C 2.A 3.C
4.C 5. B 6. A
7.D 8.B 9.B
10.(1)D (2)A (3)B
二、多選題
1.ABCFGHJ
2.BE
3.CD
4. CDE
5. AE
三、填空題
1.(S And (A>=18 And A <=20) And H>=1.65) Or (Not S And (A>=16 And Age<=18) And H>=1.60)
2. 60000
3. (1) "0" To "9" (2) "a" To "z","A" To "Z" (3) Else
4.(1)6 (2)-2 (3)2
5. Select Case x Case Is < 20
Case Is <= 0 y = 2
y = 4 Case Is <= 30
Case Is < 10 y = 3
y = 0 Case Else
Case Is < 15 y = 4
y = 1 End Select
6.(1) (x>100) And (x Mod 5=0) (2) 0
(3) Len(Text1.Text) (4) Text1.SelText
編程及上機調(diào)試
1. 在窗體上建立兩個文本框Text1(輸入數(shù))及Text2(顯示結(jié)果),一個命令按鈕Command1(“判斷”)。
Private Sub Command1_Click() '“判斷”
x = Val(Text1.Text)
If x Mod 2 = 0 Then
Text2.Text = "偶數(shù)"
Else消息
Text2.Text = "奇數(shù)"
End If
End Sub
2.窗體上建立了一個文本框Text1,用于顯示結(jié)果。
Private Sub Form_Load()
x = Val(InputBox("請輸入星期幾(0~6)"))
Select Case x
Case Is = 0
Text1.Text = "星期日(Sunday)"
Case Is = 1
Text1.Text = "星期一(Monday)"
Case Is = 2
Text1.Text = "星期二(Tuesday)"
Case Is = 3
Text1.Text = "星期三(Wednesday)"
Case Is = 4
Text1.Text = "星期四(Thursday)"
Case Is = 5
Text1.Text = "星期五(Friday)"
Case Is = 6
Text1.Text = "星期六(Saturday)"
Case Else
Text1.Text = "輸入錯誤"
End Select
End Sub
3.窗體上建立了一個文本框Text1(“輸入口令”)和一個命令按鈕Command1(“檢查”)。
Private Sub Command1_Click() '“檢查”
x = Text1.Text
If x = "12345678" Then
MsgBox ("歡迎你用機!")
Else
MsgBox ("對不起,口令錯")
End If
Text1.Text = ""
Text1.SetFocus
End Sub
Private Sub Form_Load()
Text1.Text = ""
Text1.MaxLength = 8
Text1.PasswordChar = "*"
End Sub
4.窗體上建立了兩個文本框Text1(輸入字符串)及Text2(轉(zhuǎn)換結(jié)果),一個命令按鈕Command1(“清除”)。
Private Sub Command1_Click() '“清除”
Text1.Text = ""
Text2.Text = ""
Text1.SetFocus
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
Dim s As String * 1
s = Chr(KeyAscii)
Select Case s
Case "A" To "Z"
s = LCase(s)
Case "a" To "z"
s = UCase(s)
Case Else
s = "*"
End Select
Text2.Text = Text2.Text + s
End Sub
5. 分別選擇”紅”、 ”綠”、 ”藍”復(fù)選框后,單擊命令按鈕Command1時,通過RGB函數(shù)調(diào)配的顏色作為一個標(biāo)簽的背景色(BackColor)。
Private Sub Command1_Click()
r = 0: g = 0: b = 0
If Check1.Value = 1 Then '”紅”復(fù)選框
r = 255
End If
If Check2.Value = 1 Then '”綠”復(fù)選框
g = 255
End If
If Check3.Value = 1 Then '”藍”復(fù)選框
b = 255
End If
Label1.BackColor = RGB(r, g, b)
End Sub
6.程序代碼如下:
Private Sub Form_Load()
LabClk.Caption = "0"
LabClk.Alignment = 1
LabClk.BorderStyle = 1
LabClk.FontSize = 22
LabClk.FontName = "黑體"
TimClk.Interval = 1000
End Sub
Private Sub TimClk_Timer()
LabClk.Caption = Val(LabClk.Caption) + 1
End Sub
7. (1) Chr(KeyAscii) (2) ElseIf Chr(KeyAscii)
(3) CheC = CheC - 1 (4) CheC (5) Is > 0 或 Else