以下是最新消息:
衬衫数量:(输入此处购买的衬衫数量)
优质衬衫数量:“”
帽子数量:“”
贴纸数量:“”
用户输入在文本框中购买的号码。
然后他们在选择运送选项后点击计算按钮。
计算按钮需要计算子总数,然后是销售税标签,运费标签,订单总标签。
我被困的地方是计算子总数。在我的计算按钮的计算部分,我尝试编码,但我的大脑刚停止工作或因为我被卡住了,我无法弄明白。它很简单!
这是我到目前为止的代码。一些帮助将不胜感激。我知道,代码的某些部分缺失了,因为我被卡住了。
'Local Variable Declaration Section
Const csngSalesTaxRate As Single = 0.0625
Dim sngShirtPrice As Single = 10
Dim sngPremiumShirtPrice As Single = 20
Dim sngHatPrice As Single = 15
Dim sngStickerPrice As Single = 2.99
Dim sngSubTotal As Single
Dim sngSalesTax As Single
Dim sngOrderTotal As Single
Dim sngShippingCost As Single
Dim intShirts As Integer
Dim intHats As Integer
Dim intStickers As Integer
Dim intPremiumShirts As Integer
'Data Input Section
Try 'Checks to see if the price is a valid number.
'If it is, then it is assigned to the quantity variable, if not, error message and the event is halted.
sngShirtPrice = CInt(txtShirts.Text)
Catch ex As Exception
MessageBox.Show("Please enter a valid number of Shirts.", "Error", MessageBoxButtons.OK) 'Displays an error messsage when there is an invalid number
txtShirts.Text = "" 'Clears the text box
txtShirts.Focus() 'Puts the cursor in the price textbox
Exit Sub 'Terminates the click event to allow valid input.
End Try
Try 'Checks if the quantity is a valid number.
'If it is, then it is assigned to the quantity variable, if not, error message and event is halted.
sngPremiumShirtPrice = CInt(txtPremiumShirts.Text)
Catch ex As Exception
MessageBox.Show("Please enter a valid number of Premium Shirts.", "Error", MessageBoxButtons.OK) 'Displays an error messsage when there is an invalid number
txtPremiumShirts.Text = "" 'Clears the text box
txtPremiumShirts.Focus() 'Puts the cursor in the price textbox
Exit Sub 'Terminates the click event to allow valid input.
End Try
Try 'Checks if the quantity is a valid number.
'If it is, then it is assigned to the quantity variable, if not, error message and event is halted.
sngHatPrice = CInt(txtHats.Text)
Catch ex As Exception
MessageBox.Show("Please enter a valid number of Hats.", "Error", MessageBoxButtons.OK) 'Displays an error messsage when there is an invalid number
txtHats.Text = "" 'Clears the text box
txtHats.Focus() 'Puts the cursor in the price textbox
Exit Sub 'Terminates the click event to allow valid input.
End Try
Try 'Checks if the quantity is a valid number.
'If it is, then it is assigned to the quantity variable, if not, error message and event is halted.
sngStickerPrice = CInt(txtStickers.Text)
Catch ex As Exception
MessageBox.Show("Please enter a valid number of Stickers.", "Error", MessageBoxButtons.OK) 'Displays an error messsage when there is an invalid number
txtStickers.Text = "" 'Clears the text box
txtStickers.Focus() 'Puts the cursor in the price textbox
Exit Sub 'Terminates the click event to allow valid input.
End Try
'Calculation Section
sngSubTotal = 'Calculates the subtotal
sngSalesTax = sngSubTotal * csngSalesTaxRate 'Calculates Sales Tax by multiplying Subtotal by Sales Tax Rate
sngOrderTotal = sngSubTotal + sngSalesTax 'Calculates total for the sale
mintOrdersPlacedToday = mintOrdersPlacedToday + 1 'Calculates the number of orders placed today, adds one to the previous number
'Output section
lblShowSubTotal.Text = FormatCurrency(sngSubTotal) 'Displays the Sub Total
lblShowSalesTax.Text = FormatCurrency(sngSalesTax) 'Displays the Sales Tax
lblShowOrderTotal.Text = FormatCurrency(sngOrderTotal) 'Displays the Order Total
lblShowOrdersPlacedToday.Text = mintOrdersPlacedToday
lblShowOrderTotal.Text = sngOrderTotal
End Sub
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Dim result = MessageBox.Show(" Are you sure you want to exit?", "Are you sure?", MessageBoxButtons.YesNo) 'Shows a messagebox for the user asking if they want to exit the program and gives them options.
If result = DialogResult.Yes Then 'States that if the user clicks Yes, the program will close
Me.Close() 'Exits the program
End If
End Sub
Private Sub btnClearCurentSale_Click(sender As Object, e As EventArgs) Handles btnClearCurentSale.Click
'Clears the information from current sale and resets the form for the next sale
txtShirts.Text = "" 'Clears the Shirts text box
txtPremiumShirts.Text = "" 'Clears the Premium Shirts text box
txtHats.Text = "" 'Clears the Hats text box
txtStickers.Text = "" 'Clears the Stickers text box
txtShirts.Focus() 'Puts the cursor in the Shirts text box
End Sub