VB程序设计题
95号 2.45/升 100号 2.60/升
帮帮忙哈~~~ 展开
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
Private Sub Command1_Click()
Dim price As Double
If Me.Combo1.Text = "90号" Then price = 2.3 * CLng(Me.Text1.Text)
If Me.Combo1.Text = "95号" Then price = 2.45 * CLng(Me.Text1.Text)
If Me.Combo1.Text = "100号" Then price = 2.6 * CLng(Me.Text1.Text)
Me.Text2.Text = price
End Sub
Private Sub Form_Load()
Me.Combo1.AddItem ("90号")
Me.Combo1.AddItem ("95号")
Me.Combo1.AddItem ("100号")
Me.Combo1.Text = "90号"
Me.Text1.Text = 0
Me.Text2.Text = ""
End Sub