vb程序设计测试题
Private Sub Command1_Click()
Dim n As Long
n = Val(InputBox("输入", "请输入您个年龄", 12))
If n < 18 Then
Print n; "少年"
ElseIf n >= 18 And n < 45 Then
Print n; "青年"
ElseIf n >= 45 And n <= 59 Then
Print n; "中年"
ElseIf n > 59 Then
Print n; "老年"
Else
Print n; "输入年龄错误"
End If
End Sub
Private Sub Command2_Click()
Dim n As Long
n = Val(InputBox("输入", "请输入您个年龄", 12))
Select Case n
Case Is < 18
Print n; "少年"
Case Is > 59
Print n; "老年"
Case Is >= 18
Select Case n
Case Is < 45
Print n; "青年"
Case Else
Print n; "中年"
End Select
Case Else
Print n; "输入年龄错误"
End Select
End Sub
Private Sub Form_Load()
Me.Caption = "年龄段划分"
Command1.Caption = "使用if"
Command2.Caption = "使用select"
End Sub
1.新建工程:工程1;
2.新建一下ComboBox控件:Combo1,并将属性Style改为2;
3.新建五个Label:Label1,Label2,Label3,Label4,Label5;
4.新建两个Text文本框:Text1,Text2
5.新建一个CommandButton按钮:Command1;
以上的相关控件不要改名字,位置也不用设定,程序会自动设定好。
将下面的代码COPY进去就行了
Private Sub Form_Load()
Form1.Caption = "加油站计费程序"
Form1.Width = 3800
Form1.Height = 3300
Label1.Caption = "种类"
Label1.Move 900, 200
Label1.AutoSize = 1
With Combo1
.AddItem ("90号")
.AddItem ("95号")
.AddItem ("100号")
.Move 500, 500, 1200
End With
Label2.Caption = "单价(元/升)"
Label2.Move 2000, 200
Label2.AutoSize = 1
Label3.Caption = "0"
Label3.Move 2200, 550
Label3.Width = 500
Label4.Caption = "数量"
Label4.Move 900, 1000
Label4.AutoSize = 1
Text1.Move 500, 1300, 1200, 300
Text1.Text = 0
Text1.Alignment = 1
Label5.Caption = "总价(元)"
Label5.Move 2100, 1000
Label5.AutoSize = 1
Text2.Move 1900, 1300, 1200, 300
Text2.Text = 0
Text2.Enabled = False
Text2.Alignment = 1
Command1.Caption = "计算"
Command1.Move 1320, 1920, 1095, 375
End Sub
Private Sub Combo1_Click()
Select Case Combo1.Text
Case "90号": Label3.Caption = "2.30"
Case "95号": Label3.Caption = "2.45"
Case "100号": Label3.Caption = "2.60"
End Select
Text1.SetFocus
Text1.SelLength = Len(Text1.Text)
End Sub
Private Sub Command1_Click()
On Error Resume Next
Text2.Text = Format(Val(Text1.Text) * Val(Label3.Caption), "0.00")
End Sub