vb.net - 运行程序后我需要帮助获取正确的值
问题描述
在 VB.NET 中,我需要:
- 根据售出的门票数量和门票价格计算小计。
- 根据小计计算税金。
- 通过添加税和小计来计算总计。
- 将总计添加到每日总计(运行总计)。
- 计算发起人的利润为每日总计的 20%。
- 显示小计、税收、总计、每日总计和利润。
当我运行程序并在输入售出票数和票价的值后点击提交时,小计和税金恢复正常。但是我总是在 Total Total 和 Daily Grand Total 中得到 0 的值。似乎无法弄清楚为什么。
这是我到目前为止所拥有的:
Private Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
Dim intTicketsSold As Integer
Dim dblTicketPrice As Double
Const dblTax As Double = 0.07
Dim dblOATotal As Double
Dim dblSubTotal As Double
Dim cdblDGTotal As Double
Const cdblPromoProfit As Double = 0.2
'Create local variables
intTicketsSold = txtTicketsSold.Text
dblTicketPrice = txtTicketPrice.Text
lblTax.Text = dblTax
lblOATotal.Text = dblOATotal
lblSubTotal.Text = dblSubTotal
lblDGTotal.Text = cdblDGTotal
lblPromoProfit.Text = cdblPromoProfit
'Calculate Subtotal
lblSubTotal.Text = intTicketsSold * dblTicketPrice
'calculate tax to subtotal
lblTax.Text = 0.07 * (intTicketsSold * dblTicketPrice)
'Get the overall total
dblOATotal = dblTax + dblSubTotal
'Add Total to Daily Grand Total to get Running Total
cdblDGTotal = cdblDGTotal + dblOATotal
'Calculate Promoters Profit of Daily Grand Total
lblPromoProfit.Text = 0.2 * cdblDGTotal
End Sub
我究竟做错了什么?
解决方案
Your code is not wrong, but you've forgotten to replace the content of Overall Total label and Daily Grand Total label after calculating their values, and the result of intTicketsSold * dblTicketPrice
should be saved in a variable (dblSubtotal) to use it in Overall Total calculation, that way your calculations will be correct.
Change your code like below:
Private Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
Dim intTicketsSold As Integer
Dim dblTicketPrice As Double
Const dblTax As Double = 0.07
Dim dblOATotal As Double
Dim dblSubTotal As Double
Dim cdblDGTotal As Double
Const cdblPromoProfit As Double = 0.2
'Create local variables
intTicketsSold = Convert.ToInt32(txtTicketsSold.Text)
dblTicketPrice = Convert.ToDouble(txtTicketPrice.Text)
lblTax.Text = dblTax
lblSubTotal.Text = dblSubTotal
lblPromoProfit.Text = cdblPromoProfit
'Calculate Subtotal
dblSubTotal = intTicketsSold * dblTicketPrice
lblSubTotal.Text = dblSubTotal
'calculate tax to subtotal
lblTax.Text = 0.07 * (intTicketsSold * dblTicketPrice)
'Get the overall total
dblOATotal = dblTax + dblSubTotal
lblOATotal.Text = dblOATotal
'Add Total to Daily Grand Total to get Running Total
cdblDGTotal = cdblDGTotal + dblOATotal
lblDGTotal.Text = cdblDGTotal
'Calculate Promoters Profit of Daily Grand Total
lblPromoProfit.Text = 0.2 * cdblDGTotal
End Sub
推荐阅读
- python - 如何在neural_tangent.stax 框架中指定输入维度?
- reactjs - NextJS:将新的查询字符串值推送到现有的 asPath 或更新现有的查询字符串
- angular - 角度和引导模式
- thymeleaf - 如何在 Thymeleaf 中的每 N 次迭代后更改 Row?
- image - 如何确保 Sphinx 文档中的图像文件在 LaTeX pdf 中“自动”复制
- javascript - 遍历有条件的对象的对象
- xcode - Xcode 在最新升级中丢失了一些模拟器
- types - Haxe:检查动态类型是否为对象
- angular - 用户登录但令牌在使用角度中的 JWT auth 刷新之前未更改
- ruby - 在Ruby中的一行中循环遍历数组的代码