习题一
一、填空题
1.“控件工具箱”、“窗体设计器”、“工程资源管理器”、“属性窗口”、“窗体布局窗口”、“代码编辑器”“立即”、“本地”和“监视”窗口等
2.三;设计(Design)模式、运行模式(Run)和中断(Break)模式
3、工程1;1;Form1
4、选择菜单“视图|立即窗口”即可打开“立即”窗口;它是Visual Basic中的一个系统对象,叫Debug对象,可以在调试程序时使用它,通常使用Print方法向立即窗口中输出程序的信息,还可以将语句直接写在“立即”窗口上,按“回车”键后,这行语句会被立刻执行。 5、查看代码、查看对象;“查看对象”按钮;“查看代码”按钮 二、选择题
1.B 2.C 3.D 4.B 5.C 6.B 7.D 三、程序设计题 1.
Private Sub Command1_Click() Text1.Text = \欢迎使用VB!\End Sub
Private Sub Command2_Click() Text1.Text = \End Sub
Private Sub Command3_Click() End End Sub 2.
Private Sub Command1_Click()
Label1.Caption = \你好,张三!\ Command1.Enabled = False End Sub
Private Sub Command2_Click() Label1.Visible = False Command3.Enabled = True Command2.Enabled = False End Sub
Private Sub Command3_Click() Label1.Visible = True Command2.Enabled = True Command3.Enabled = False End Sub 习题二
一、填空题 1. 0
2. “除数为零”错误 3. Long 4. False
5. Const PI = 3.14159 6. True 7. 4 8. 4
9. Dim Mystr As String*10 10. True
11. 1<=x And x<=5 二、程序设计题 1.
Private Sub Command1_Click() Label1.Left = Label1.Left - 100 End Sub
Private Sub Command2_Click() Label1.Left = Label1.Left + 100 End Sub
Private Sub Command3_Click() Label1.Top = Label1.Top - 100 End Sub
Private Sub Command4_Click() Label1.Top = Label1.Top + 100 End Sub
2.
Private Sub Command1_Click()
Label1.Caption = \百位数:\十位数:\\个位数:\End Sub 3.
Private Sub Command1_Click()
Dim a As Single, b As Single, c As Single a = Text1.Text b = Text2.Text c = a + b
Label1.Caption = \ Text3.Text = c
End Sub
Private Sub Command2_Click()
Dim a As Single, b As Single, c As Single a = Text1.Text b = Text2.Text c = a - b
Label1.Caption = \ Text3.Text = c End Sub
Private Sub Command3_Click()
Dim a As Single, b As Single, c As Single a = Text1.Text b = Text2.Text c = a * b
Label1.Caption = \ Text3.Text = c End Sub
Private Sub Command4_Click()
Dim a As Single, b As Single, c As Single a = Text1.Text b = Text2.Text c = a / b
Label1.Caption = \ Text3.Text = c
End Sub
Private Sub Command5_Click() Text1.Text = \ Text2.Text = \ Text3.Text = \End Sub
Private Sub Command6_Click() End End Sub 4.
Private Sub Command1_Click()
Dim c As String
c = InputBox(\输入带区号的电话号码,“0571-86281517”:\
号为4为,号码为8位,如输入区比 MsgBox (\区号:\号码:\End Sub
二、程序填空 1.
(1)i >= 0 (2)i < iMin 2.
(1)i >= 0 (2)i < iMin 3.
Private Sub Command1_Click()
Dim str1 As String, str2 As String str1 = Text1.Text str2 = \
m = 0
Do While m < Len(str1) / 2
str2 = str2 + Mid(str1, m + 1, 1)
str2 = str2 + Mid(str1, Len(str1) - m, 1) m = m + 1 Loop
Form1.Print str2 End Sub 4.
Private Sub Command1_Click()
Dim str1 As String, str2 As String str1 = Text1.Text str2 = \
m = 0
Do While m < Len(str1) / 2
str2 = str2 + Mid(str1, m + 1, 1) str2 = str2 + Mid(str1, Len(str1) - m, 1) m = m + 1 Loop
Form1.Print str2 End Sub 5.
Private Sub Form_Click() Dim i As Integer Dim k As Single Dim p As Integer Dim s As Single p = 1 s = 0
For i = 1 To 100 k = p / i p = -p s = s + k Next i
Form1.Print \End Sub
三、程序设计 1.
Private Sub Form_Click()
Dim x As Single, y As Single x = InputBox(\ If x > 10 Then
y = Sqr(x) + Sin(x * 3.14 / 180) ElseIf x = 0 Then y = 0 Else
y = 2 * x ^ 3 + 6 End If Print y
End Sub 2.
Private Sub Form_Click()
Dim i As Integer, n As Integer, m As Integer, s As Integer n = InputBox(\
Randomize For i = 1 To n
m = Int(Rnd * 90) + 10 If m Mod 2 = 0 Then s = s + m Next i
Label1.Caption = s End Sub 3.
Private Sub Command1_Click()
Dim i As Integer, n As Integer, a As Integer, b As Integer, c As Integer For i = 1 To 100 n = InputBox(\ If n >= 85 Then a = a + 1
ElseIf n >= 60 Then b = b + 1