gpt4 book ai didi

vb.net - VB 2010 中的计算问题

转载 作者:行者123 更新时间:2023-12-02 11:36:52 28 4
gpt4 key购买 nike

我无法弄清楚这段代码的问题出在哪里。我的计算一直运行良好,直到最后一种情况 (CASE IS > 8),该情况连续返回 0.00 作为结果。我确信像我这样的新手由于缺乏经验而缺少一些小东西。感谢您的帮助!

' Declaration of Variable

Convert.ToInt32(txtAttending.Text)
Dim decAttending = txtAttending.Text

If IsNumeric(txtAttending.Text) And txtAttending.Text <= 16 Then
Select Case txtAttending.Text
Case Is = 1
decCost = 695 * decAttending
Case 2 To 4
decCost = 545 * decAttending
Case 5 To 8
decCost = 480 * decAttending
Case Is > 8
decCost = 395 * decAttending
End Select
Else
MsgBox("Please double check that your input is a number not greater than 16", , "Input Error")

End If

If radYes.Checked = True Then
decFinalCost = (decCost - (decCost * 0.15))
lblRepeatDiscount.Visible = True
decDiscount = (decCost * 0.15)
lblDiscount.Text = decDiscount.ToString("C")
lblTotalPrice.Text = decFinalCost.ToString("C")

Else
decFinalCost = decCost
lblTotalPrice.Text = decFinalCost.ToString("C")
End If

最佳答案

Convert.ToInt32(txtAttending.Text) 不会就地转换文本,正如您的第一行代码似乎断言的那样;这是一个空操作。 txtAttending.Text 的类型为 System.String,并且将始终具有该类型。

您的案例陈述应该看起来更像这样:

If IsNumeric(txtAttending.Text) Then

Dim decAttending = Convert.ToInt32(txtAttending.Text)

Select Case decAttending
Case Is = 1
decCost = 695 * decAttending
Case 2 To 4
decCost = 545 * decAttending
Case 5 To 8
decCost = 480 * decAttending
Case 9 To 16
decCost = 395 * decAttending
End Select
Else
MsgBox("Please double check that your input is a number not greater than 16", , "Input Error")

此版本在进行数值运算时始终使用 System.Int32 变量 decAttending

关于vb.net - VB 2010 中的计算问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9969550/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com