您的当前位置:首页正文

vb选择结构练习题

2021-07-04 来源:我们爱旅游
1.奖学金问题; 平均分大于95

或者两门100 一门大于80分

Private Sub Command1_Click() m1 = Val(Text1.Text) m2 = Val(Text2.Text) m3 = Val(Text3.Text) x = (m1 + m2 + m3) / 3 If x > 95 Then y = 1

ElseIf m1 = 100 And m2 = 100 And m3 >= 80 Then y = 1

ElseIf m2 = 100 And m3 = 100 And m1 >= 80 Then y = 1

ElseIf m1 = 100 And m3 = 100 And m2 >= 80 Then y = 1 Else

y = 0 End If

If y = 1 Then

Text4.Text = \"一等奖学金\"

Else: Text4.Text = \"非一等奖学金\" End If End Sub

2.三个数比较大小 并按从小到大排列

Private Sub Command1_Click() x = Val(Text1.Text) y = Val(Text2.Text) z = Val(Text3.Text) tmax = IIf(x > y, x, y)

Max = IIf(tmax > z, tmax, z) tmin = IIf(x < y, x, y)

Min = IIf(tmin < z, tmin, z) a = x + y + z - Min - Max

Text4.Text = Min & \" < \" & a & \" < \" & Max

End Sub

3.编写一个简单计算器程序

Private Sub Command1_Click() num1 = Val(Text1.Text) num2 = Val(Text2.Text) NOp = Trim(Text3) Select Case NOp Case \"+\"

x = num1 + num2 Case \"-\"

x = num1 - num2

Case \"*\"

x = num1 * num2 Case \"/\"

x = num1 / num2 End Select Text4.Text = x End Sub

Private Sub Command2_Click() Text1.Text = \"\" Text2.Text = \"\" Text3.Text = \"\" Text4.Text = \"\" End Sub

4.输入一个数字,用英文显示对应的周一至周日

Private Sub Command1_Click() a = Val(Text1.Text) Select Case a Case 1

Text2.Text = \"Monday\" Case 2

Text2.Text = \"Tuesday\" Case 3

Text2.Text = \"wednesday\" Case 4

Text2.Text = \"Thursday\" Case 5

Text2.Text = \"Friday\" Case 6

Text2.Text = \"Saturday\" Case 7

Text2.Text = \"Sunday\" Case Is > 7, Is < 1 Text2.Text = \"error\" End Select End Sub

Private Sub Command2_Click() Text1.Text = \"\" Text2.Text = \"\" End Sub

5.公用电话收费程序,3分钟以内0.5元,超过部分每分钟加收0.15元,在7点至19之间正常收费,其他时间半价收费

Private Sub Command1_Click() a1 = Text1 b1 = Text2 c1 = Text3 a2 = Text4 b2 = Text5 c2 = Text6

s = (a2 - a1) * 60 + (b2 - b1) + (c2 - c1) / 60 Text7 = s If s <= 3 Then

m = 0.5 Else

m = 0.5 + (s - 3) * 0.15 End If

If a1 > 19 Or a1 < 7 Then m = m / 2 End If

Text8 = m

End Sub

Private Sub Command2_Click() Text1 = \"\" Text2 = \"\" Text3 = \"\" Text4 = \"\" Text5 = \"\" Text6 = \"\" Text7 = \"\" Text8 = \"\" End Sub

因篇幅问题不能全部显示,请点此查看更多更全内容