MSGBOX не работает должным образом при клике заказа - PullRequest
0 голосов
/ 26 марта 2019

У меня есть кнопка заказа, которая определит цену товара, а затем представит пользователю детали заказа. Однако мой 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

1 Ответ

0 голосов
/ 26 марта 2019

Я добавил строку, которая инициирует окно сообщения, используя ранее созданную вами строку.

Чтобы узнать больше о окнах сообщений и их использовании, ознакомьтесь с этой страницей MDOCS !

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"
...