大学计算机VB程序设计考试题目
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
实验三
第1题四则运算题
设计如下窗体,为五个命令按钮编写5段代码完成四则运算及退出程序,其中在计算除法时,如果第二个数就是零,在消息框中显示信息“除数为零”。
Public Class Form1
Private Sub Button1_Click(ByVal sender As System、Object, ByVal e As System、EventArgs) Handles Button1、Click
Dim a, b As Single
a = TextBox1、Text
b = TextBox2、Text
TextBox3、Text = a + b
End Sub
Private Sub Button2_Click(ByVal sender As System、Object, ByVal e As System、EventArgs) Handles Button2、Click
Dim a, b As Single
a = TextBox1、Text
b = TextBox2、Text
TextBox3、Text = a - b
End Sub
Private Sub Button3_Click(ByVal sender As System、Object, ByVal e As System、EventArgs) Handles Button3、Click
Dim a, b As Single
a = TextBox1、Text
b = TextBox2、Text
TextBox3、Text = a * b
End Sub
Private Sub Button4_Click(ByVal sender As System、Object, ByVal e As System、EventArgs) Handles Button4、Click
Dim a, b As Single
a = TextBox1、Text
b = TextBox2、Text
If b = 0 Then
MessageBox、Show("除数为零")
Else
TextBox3、Text = a / b
End If
End Sub
Private Sub Button5_Click(ByVal sender As System、Object, ByVal e As System、EventArgs) Handles Button5、Click
End
End Sub
End Class
第2题一元二次方程求解
输入系数后,单击“求解”按钮后,根据判别式的3种不同情况,分别显示如下的不同结果。
Public Class Form1
Private Sub Button1_Click(ByVal sender As System、Object, ByVal e As System、EventArgs) Handles Button1、Click
Dim a, b, c, delta As Double
a = TextBox1、Text
b = TextBox2、Text
c = TextBox3、Text
delta = b * b - 4 * a * c
If delta > 0 Then
Label5、Visible = True
Label6、Visible = True
Label4、Text = "方程有两个不相等实根"
Label5、Text = "X1=" & ((-b + Math、Sqrt(delta)) / 2 / a)
Label6、Text = "X2=" & ((-b - Math、Sqrt(delta)) / 2 / a)
ElseIf delta = 0 Then
Label4、Text = "方程有两个相等实根"
Label5、Visible = True
Label5、Text = "X1=X2=" & (-b / 2 / a)
Label6、Visible = False
Else
Label4、Text = "方程没有实根"
Label5、Visible = False
Label6、Visible = False
End If
End Sub
Private Sub Button2_Click(ByVal sender As System、Object, ByVal e As System、EventArgs) Handles Button2、Click
End
End Sub
End Class
第3题文本框中前景色与背景色的不同组合
目的:单选按钮的使用
(1)设计窗体
如下所示窗体中包含两组单选按钮、两个框架与一个命令按钮。
(2)程序功能:
分别单击不同的前景色与背景色按钮,在文本框中显示颜色的改变。
(3)设置控件的主要属性
1)窗体的文本属性为“不同前景色背景色的组合”
2)初始前景色为红色、背景色为黄色
3)其它属性根据图中显示来设置
(4)事件代码
Public Class Form1
Private Sub RadioButton1_CheckedChanged(ByVal sender As System、Object, ByVal e As System、EventArgs) Handles RadioButton1、CheckedChanged
TextBox1、ForeColor = Color、Red
End Sub
Private Sub RadioButton2_CheckedChanged(ByVal sender As System、Object, ByVal e As System、EventArgs) Handles RadioButton2、CheckedChanged
TextBox1、ForeColor = Color、Green
End Sub
Private Sub RadioButton3_CheckedChanged(ByVal sender As System、Object, ByVal e As System、EventArgs) Handles RadioButton3、CheckedChanged
TextBox1、ForeColor = Color、Black
End Sub
Private Sub RadioButton4_CheckedChanged(ByVal sender As System、Object, ByVal e As System、EventArgs) Handles RadioButton4、CheckedChanged
TextBox1、BackColor = Color、White
End Sub
Private Sub RadioButton5_CheckedChanged(ByVal sender As System、Object, ByVal e As System、EventArgs) Handles RadioButton5、CheckedChanged
TextBox1、BackColor = Color、Yellow
End Sub
Private Sub Form1_Load(ByVal sender As System、Object, ByVal e As System、EventArgs) Handles MyBase、Load
End Sub
End Class
第4题三位整数的反序显示
在窗体中添加二个文本框、二个标签与一个命令按钮,在一个文本框