订单点击时MSGBOX无法正常工作

问题描述 投票:0回答:1

我有一个订单按钮,可以确定产品的价格,然后向用户显示订单详细信息。但是,我的MSG BOX无效。

Sub ButtonOrder_Click()
    Dim TotalOrdered As Integer
    Dim Price As Single
    Dim StrMsg As String
    Const OrderPrice = 2.5
    Const TaxRate = 0.06
    Const TaxRateMultiplier = 1.06

    With ThisWorkbook.Sheets("Form")
        If (Len(.Range("B2")) = 0) Then
            Range("B2") = InputBox("Enter your name:  ")
        ElseIf (Len(.Range("B3")) = 0) Then
            Range("B3") = InputBox("Please enter your email: )
        ElseIf (Len(.Range("B4")) = 0) Then
            Range("B4") = InputBox("Please Enter Chocolate Amount:  )
        ElseIf (Len(.Range("B5")) = 0) Then
            Range("B5") = InputBox("Please Enter Vanilla Amount : )
        ElseIf (Len(.Range("B6")) = 0) Then
            Range("B6") = InputBox("Please Enter Strawberry Amount: )
        Else
            TotalOrdered = Range("B4").Value + Range("B5").Value + Range("B6").Value
            Exit Sub
        End If
    End With

    'goes through checking the order and number and discount amount
    Select Case Price
        Case TotalOrdered >= 6 And TotalOrdered <= 10
            Price = TotalOrdered * OrderPrice * 0.95
        Case TotalOrdered >= 11 And TotalOrdered <= 20
            Price = TotalOrdered * OrderPrice * 0.9
        Case TotalOrdered >= 21
            Price = TotalOrdered * OrderPrice * 0.8
        Case Else 'less than 6
            Price = TotalOrdered * OrderPrice
           End Select

    'I incorporated the unit price with discount so it is more informative for the customer
    StrMsg = ("Unit Price: $" & Price / TotalOrdered _ 'format function from HW 2
    & "Quantity: " & TotalOrdered _
    & "Tax Rate: $" & TaxRate _
    & "Final Total Price: " & Price * TaxRateMultiplier)

End Sub
vba loops case msgbox
1个回答
0
投票

我已经使用您预先构建的字符串添加了启动消息框的行。

要阅读有关消息框以及如何使用它们的更多信息,请查看this MDOCS page

With ThisWorkbook.Sheets("Form")
    If Len(.Range("B2")) = 0 Then
        .Range("B2") = InputBox("Enter your name:  ")
    ElseIf Len(.Range("B3")) = 0 Then
        .Range("B3") = InputBox("Please enter your email: ")
    ElseIf Len(.Range("B4")) = 0 Then
        .Range("B4") = InputBox("Please Enter Chocolate Amount:  ")
    ElseIf Len(.Range("B5")) = 0 Then
        Range("B5") = InputBox("Please Enter Vanilla Amount : ")
    ElseIf Len(.Range("B6")) = 0 Then
        Range("B6") = InputBox("Please Enter Strawberry Amount: ")
    Else
        TotalOrdered = .Range("B4").Value + .Range("B5").Value + .Range("B6").Value
        Exit Sub
    End If
End With

'goes through checking the order and number and discount amount
Select Case Price
    Case TotalOrdered >= 6 And TotalOrdered <= 10
        Price = TotalOrdered * OrderPrice * 0.95
    Case TotalOrdered >= 11 And TotalOrdered <= 20
        Price = TotalOrdered * OrderPrice * 0.9
    Case TotalOrdered >= 21
        Price = TotalOrdered * OrderPrice * 0.8
    Case Else 'less than 6
        Price = TotalOrdered * OrderPrice
       End Select

'I incorporated the unit price with discount so it is more informative for the customer
StrMsg = ("Unit Price: $" & Price / TotalOrdered _ 'format function from HW 2
& "Quantity: " & TotalOrdered _
& "Tax Rate: $" & TaxRate _
& "Final Total Price: " & Price * TaxRateMultiplier)

MsgBox strMsg, vbInformation, "Prices"
© www.soinside.com 2019 - 2024. All rights reserved.