当前位置:文档之家› VisualBasic程序设计作业复习资料

VisualBasic程序设计作业复习资料

Visual Basic程序设计作业答案
作业2
一、选择题
1.B 2.C 3.D 4.B 5.D 6.A 7.B 8.C 9.A 10.D 11.C 12.B 13.D 14.C 15.A 16.B 17.C 18.B 19.D 20.B
二、填空题
1.下拉式菜单弹出式菜单
2.打开另存为颜色字体打印
3.文本框列表框
4.Option Base 1
5.Call语句
6.工程工程属性通用Form1.Show
7.0
8.Sub过程的过程名不能返回值,而Function过程能通过过程名返回值
9.窗体模块标准模块类模块
10.移出内存无效状态
11.(1)2*Cosα*Sinα/(2*α)
(2) Sqr(s*(s-a)*(s-b)*(s-c))
(3) Sin(45*3.14/180)
12.(1)x>=1 And x<12
(2) A+B>=C Or a-c<=c
(3) a>0 And b>0 Or(a<0 And b<0)
13.False
14.For While Do
15.3
三、阅读下列程序,给出程序运行结果。

1.程序运行后,单击窗体,输出结果为:5050。

2.
3.
4.
3.4 3
5.
*
***
*****
*******
*********
四、程序设计题
1.
Private Sub Command1_Click()
Dim x As Single, y As Single
x = Val(Text1.Text)
If x < 100 Then
y = x
Else
If x < 200 Then
y = 9.5 * x
Else
If x < 300 Then
y = 0.9 * x
Else
If x < 500 Then
y = 0.8 * x
Else
y = 0.7 * x
End If
End If
End If
End If
Text2.Text = y
End Sub
2.
Private Sub Form_Load()
Dim x As Integer
x = 100
Do Until x > 200
If x Mod 3 <> 0 Then
Text1.Text = Text1.Text & Str(x) & Chr(13) & Chr(10)
End If
x = x + 1
Loop
End Sub
3.
Private Sub Form_Click()
Print "*";Tab(9);3,Tab(18);6;Tab(27);9;Tab(36);12
Print
For I=15 to 18
Print I;
For j=3 to 12 Step 3
Print Tab(3*j);j*I;
Next j
Print
Next I
End sub
4.
Private Sub Command1_Click()
Unload Me
End Sub
Private Sub Option1_Click()
Text1.Text = 10 * 2
End Sub
Private Sub Option2_Click()
Text1.Text = 10 / 2
End Sub
Private Sub Option3_Click()
Text1.Text = 10 + 2
End Sub
Private Sub Option4_Click()
Text1.Text = 10 - 2
End Sub
5.
Private Function Day(n As Integer)
Select Case n
Case 0
Day = "星期日" & Chr(13) & "(Sunday)"
Case 1
Day = "星期一" & Chr(13) & "(Monday)"
Case 2
Day = "星期二" & Chr(13) & "(Tuesday)"
Case 3
Day = "星期三" & Chr(13) & "(Wednesday)"
Case 4
Day = "星期四" & Chr(13) & "(Thursday)"
Case 5
Day = "星期五" & Chr(13) & "(Friday)"
Case 6
Day = "星期六" & Chr(13) & "(Saturday)"
End Select
End Function
Private Sub Text1_KeyPress(KeyAscii As Integer)
Dim n As Integer
n = Val(Text1.Text)
If KeyAscii = 13 Then
If n >= 0 And n < 7 Then
Label1.Caption = Day(n)
Else
MsgBox "请输入0~6之间的整数!"
End If
End If
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
End Sub
6.
新建一个工程,在默认的窗体Form1上放置一个Picture控件,然后编写如下代码。

Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 2 Then
MsgBox "You pressed right Button"
Picture1.MousePointer = vbArrow
End If
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Picture1.MousePointer = vbUpArrow
End Sub
7.
Private Sub Form_Load()
List1.AddItem "李敏"
List1.AddItem "张华"
List1.AddItem "吕晓烨"
List1.AddItem "赵巍"
List1.AddItem "袁莉"
List1.AddItem "王津"
List1.AddItem "何小渴"
List1.AddItem "崔宁"
List1.AddItem "陈曦"
List1.AddItem "刘伟楠"
End Sub
Private Sub Command1_Click()
If Text1.Text <> "" Then
List1.AddItem Text1.Text
Text1.Text = ""
Else
MsgBox "请在文本框中输入信息!" End If
End Sub
Private Sub Command2_Click()
List1.RemoveItem List1.ListIndex
End Sub
Private Sub Command3_Click()
If Command3.Caption = "修改" Then
Text1.Text = List1.Text
Text1.SetFocus
Command1.Enabled = False
Command2.Enabled = False
Command3.Caption = "修改确认"
Else
List1.List(List1.ListIndex) = Text1.Text
Command1.Enabled = True
Command2.Enabled = True
Text1.Text = ""
Command3.Caption = "修改"
End If
End Sub
Private Sub List1_Click()
If List1.ListIndex <> -1 Then
Command2.Enabled = True
Command3.Enabled = True
End If
End Sub。

相关主题