资源描述
1.输入语文、数学、英语的成绩,点击计算求总分和平均分。
Private Sub Command1_Click()
Dim yu As Double
Dim shu As Double
Dim ying As Double
Dim zong As Double
yu = Val(Text1.Text)
shu = Val(Text2.Text)
ying = Val(Text3.Text)
zong = yu + shu + ying
pin = zong / 3
Text4.Text = zong
Text5.Text = pin
End Sub
2.点击显示按钮在文本框中显示欢迎进入VB世界!点击清除按钮欢迎进入VB世界!消失。
Private Sub Command1_Click()
Text1.Text = "欢迎进入VB世界!"
End Sub
Private Sub Command2_Click()
Text1.Text = ""
End Sub
3. 编写一个程序根据用户输入的两个数,然后输出较大的数。
Private Sub Command1_Click()
Dim a As Double
Dim b As Double
Dim max As Double
a = Val(Text1.Text)
b = Val(Text2.Text)
If a > b Then
max = a
Else
max = b
End If
Text3.Text = max
End Sub
第二题:编写一个程序,根据用户输入的某个学生的成绩评出优、良好、中等、及格和不及格五个等级。判断标准如下:
不及格(E) score<60
及格(D) 60≤score<70
中等(C) 70≤score<80
良好(B) 80≤score<90
优 (A) score≥90
Private Sub Command1_Click()
Dim score As Double
Dim degree As String
score = Val(Text1.Text)
Select Case score
Case Is < 60
degree = "成绩等级为E"
Case 60 To 69
degree = "成绩等级为D"
Case 70 To 79
degree = "成绩等级为C"
Case 80 To 89
degree = "成绩等级为B"
Case 90 To 100
degree = "成绩等级为A"
Case Else
degree = "输入成绩有错"
End Select
Text2.Text = degree
End Sub
1.用Select Case语句编程为某航空公司计算票价的优惠率R。假设优惠规定如下。
(1)在旅游的旺季7~9月份,如果订票数超过20张,票价优惠15%;20张以下,优惠5%。
(2)在旅游的淡季1~5月份、10月份和11月份,如果订票数超过20张,票价优惠30%;20张以下,优惠20%。
(3)其他情况一律优惠10%。
(注意:设计程序时,根据月份和订票张数决定票价的优惠率。)
建立应用程序用户界面并设置对象属性,如图所示。
Dim m As Integer
Dim n As Integer
Dim r As Integer
m = Val(Text1.Text)
n = Val(Text2.Text)
Select Case m
Case 7 To 9
If n > 20 Then
r = 15
Else
r = 5
End If
Case 1 To 5, 10, 11
If n > 20 Then
r = 30
Else
r = 20
End If
Case Else
r = 10
End Select
Label4.Caption = Label4.Caption & r & "%"
End Sub
1.请设计一个如图 1 与图 2 所示的下拉菜单,各菜单的名称属性如表 1所示,要求使
用菜单编辑器设置各级菜单及相应热键。
图1文件下拉菜单
图2文件下拉菜单
标题
名称
上级菜单标题
热键
快捷键
文件
Mfile
无
F
无
新建
MNew
文件
N
CtrL+N
打开
MOpen
文件
O
CtrL+O
保存
MSave
文件
S
CtrL+S
关闭
MClose
文件
C
CtrL+C
分割线
MSp1
文件
无
无
退出
MExit
文件
E
CtrL+E
格式
MChar
无
H
无
居左
MLeft
格式
L
CtrL+L
居右
MRight
格式
R
CtrL+R
居中
MCenter
格式
M
CtrL+M
分割线
MSp2
格式
无
无
字体
MFont
格式
T
CtrL+T
2,输入三个数,求其中最大数。界面如下图所示:
Private Sub Command1_Click()
Dim a As Integer
Dim b As Integer
Dim c As Integer
Dim max As Integer
a = Val(Text1.Text)
b = Val(Text2.Text)
c = Val(Text3.Text)
max = a
If max < b Then max = b
If max < c Then max = c
Text4.Text = max
End Sub
10. 编写程序,求出100之内的所有勾股数。(勾股数:a2+b2=c2,a、b、c为自然数,且a<>b)
Dim a As Integer
Dim b As Integer
Dim c As Integer
For a = 1 To 100
For b = 1 To 100
For c = 1 To 100
If a ^ 2 + b ^ 2 = c ^ 2 And a <> b Then
Print a, b, c; "是勾股数"
End If
Next c
Next b
Next a
End Sub
1. 使用Rnd函数生成5个 [0~100]之间的随机整数,找出这5个数中的最大数与最小数,并以升序重新排列这5个数。窗体格式如图(9分)
参考答案:
‘*****界面设计(1分)**************
Option Explicit
Option Base 1
Dim a(5) As Integer
Private Sub Command1_Click()
Dim max As Integer ‘存储最大数
Dim min As Integer ‘存储最小数
Dim i As Integer ‘循环变量
Dim j As Integer ‘循环变量
Dim t As Integer ‘交换变量
Dim s As String ‘存储排序后的5个数
‘****求最大最小值(2分)**********
max = 0
min = 100
For i = 1 To 5
If max < a(i) Then max = a(i)
If min > a(i) Then min = a(i)
Next i
Text1.Text = max
Text2.Text = min
‘************************
‘*****排序(2分)*********
For i = 1 To 5
For j = i + 1 To 5
If a(i) > a(j) Then
t = a(i)
a(i) = a(j)
a(j) = t
End If
Next j
Next i
For i = 1 To 5
s = s + Str(a(i))
Next i
Label4.Caption = s
‘****************
End Sub
Private Sub Form_Load()
Dim i As Integer
Dim s As String
Label3.FontSize = 18
Label4.FontSize = 18
Text1.FontSize = 18
Text2.FontSize = 18
‘*****初始化随机数(2分)*******
For i = 1 To 5
a(i) = Int(Rnd * 101)
s = s + Str(a(i))
Next i
Label3.Caption = s
‘********************************
End Sub
If Index = 0 Then
Randomize
For i = 0 To 6
Label1(i).Caption = Int(10 * Rnd)
Next i
Else
Unload Me
End If
展开阅读全文