展开全部
新建工程,只有1个label1,代码如下:
Private Sub Command1_Click()
Dim a1!, a2!, b1!, b2!, c1!, c2!
reinput:
a1 = Val(InputBox("请输入商品1的单价!!"))
a2 = Val(InputBox("请输入商品1的数量!!"))
b1 = Val(InputBox("请输入商品2的单价!!"))
b2 = Val(InputBox("请输入商品2的数量!!"))
c1 = Val(InputBox("请输入商品3的单价!!"))
c2 = Val(InputBox("请输入商品3的数量!!"))
If IsNumeric(a1) = False Or IsNumeric(a2) = False Or IsNumeric(b1) = False Or _
IsNumeric(b2) = False Or IsNumeric(c1) = False Or IsNumeric(c2) = False Then
MsgBox "你输入的有问题,请重新输入!!"
GoTo reinput
End If
Label1.AutoSize = True
Label1.Caption = "商品1的单价为:" & a1 & " , 商品1的数量为:" & a2 & vbCrLf
Label1.Caption = Label1.Caption & "商品2的单价为:" & b1 & " , 商品2的数量为:" & b2 & vbCrLf
Label1.Caption = Label1.Caption & "商品3的单价为:" & c1 & " , 商品2的数量为:" & c2 & vbCrLf
Label1.Caption = Label1.Caption & "合计金额为:" & a1 * a2 + b1 * b2 + c1 * c2
End Sub
Private Sub Command1_Click()
Dim a1!, a2!, b1!, b2!, c1!, c2!
reinput:
a1 = Val(InputBox("请输入商品1的单价!!"))
a2 = Val(InputBox("请输入商品1的数量!!"))
b1 = Val(InputBox("请输入商品2的单价!!"))
b2 = Val(InputBox("请输入商品2的数量!!"))
c1 = Val(InputBox("请输入商品3的单价!!"))
c2 = Val(InputBox("请输入商品3的数量!!"))
If IsNumeric(a1) = False Or IsNumeric(a2) = False Or IsNumeric(b1) = False Or _
IsNumeric(b2) = False Or IsNumeric(c1) = False Or IsNumeric(c2) = False Then
MsgBox "你输入的有问题,请重新输入!!"
GoTo reinput
End If
Label1.AutoSize = True
Label1.Caption = "商品1的单价为:" & a1 & " , 商品1的数量为:" & a2 & vbCrLf
Label1.Caption = Label1.Caption & "商品2的单价为:" & b1 & " , 商品2的数量为:" & b2 & vbCrLf
Label1.Caption = Label1.Caption & "商品3的单价为:" & c1 & " , 商品2的数量为:" & c2 & vbCrLf
Label1.Caption = Label1.Caption & "合计金额为:" & a1 * a2 + b1 * b2 + c1 * c2
End Sub
展开全部
在窗体上放一个标签控件label1.程序运行单击窗体要求输入数据。
把代码直接复制到窗体即可。代码如下:
Private Sub Form_Click()
Dim a, i As Integer
Dim b, sum As Single
For i = 1 To 3
a = Val(InputBox("请输入第" & i & "个商品的单价。"))
b = Val(InputBox("请输入第" & i & "个商品的数量。"))
sum = sum + a * b
Next i
Label1.Visible = True
Label1.Caption = "一共:" & sum
End Sub
Private Sub Form_Load()
Label1.Visible = False
End Sub
把代码直接复制到窗体即可。代码如下:
Private Sub Form_Click()
Dim a, i As Integer
Dim b, sum As Single
For i = 1 To 3
a = Val(InputBox("请输入第" & i & "个商品的单价。"))
b = Val(InputBox("请输入第" & i & "个商品的数量。"))
sum = sum + a * b
Next i
Label1.Visible = True
Label1.Caption = "一共:" & sum
End Sub
Private Sub Form_Load()
Label1.Visible = False
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Dim How As Double
For n = 1 To 3
A = InputBox("请输入第" & n & "种商品价格", "", "")
B = InputBox("请输入第" & n & "种商品数量", "", "")
How = How + A * B
Next
MsgBox How
For n = 1 To 3
A = InputBox("请输入第" & n & "种商品价格", "", "")
B = InputBox("请输入第" & n & "种商品数量", "", "")
How = How + A * B
Next
MsgBox How
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询