【问题标题】:I cannot get my message box to appear at the correct instance (Beginner)我无法让我的消息框出现在正确的实例中(初学者)
【发布时间】:2023-03-17 19:25:01
【问题描述】:

我正在编写一个小型应用程序,但我无法让我的消息框在正确的时间工作,当它出现时,标签仍然会更新。它快把我逼疯了!消息框需要显示小于 19 天和大于 22 天的天数。两个底部错误确实可以正常工作,至少我确实相信它们之前确实可以正常工作(在我试图让其他错误工作之前)。下面是我的代码。当输入的数字小于 19 且大于 22 btw 时,我需要出现上述错误(消息框)。

谢谢你:)。这是在 vb.net 顺便说一句。

'Date: 3/21/2015
'Purpose: The application finds the amount of a monthly pau if you are paid on a penny or nickel a day for the first workday then the pay is doubled each workday.
'    Inexpereinced workers are paid a penny a day, experienced workers are paid a nickel. 


Option Explicit On


Public Class frmPennyOrNickelADay

    Const _cdecPenny As Decimal = 0.01D
    Const _cdecNickel As Decimal = 0.05D
    Const _cDecDoubledAmount As Decimal = 2D
    Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
        Dim decSalary As Decimal = 0
        Dim intDay As Integer
        Dim decPenny As Decimal = 0.01D
        Dim decNickel As Decimal = 0.05D
        Dim decDouble As Decimal = 2
        Dim intRunningTally As Integer
        Dim decMaxNumber As Decimal
        If IsNumeric(txtDaysWorkedUserEntry.Text) = True Then
            intDay = Convert.ToInt32(txtDaysWorkedUserEntry.Text)
            If intDay > 0 Then
                If radPenny.Checked = True Then
                    If intDay < 19 Then
                        MessageBox.Show("Error", "input error", MessageBoxButtons.OK)
                        lblAmountEarnedResult.Text = ""

                    End If
                End If
                If radPenny.Checked = True Then
                    decSalary = decPenny

                ElseIf radNickel.Checked = True Then
                    decSalary = decNickel
                End If

                For intDay = 1 To intDay
                    If intDay = 1 Then
                        decSalary = decSalary
                    Else
                        decSalary *= decDouble
                    End If
                    intRunningTally += decSalary

                Next

                lblAmountEarnedResult.Text = decSalary.ToString("C2")
            Else
                MessageBox.Show("Please enter a number greater than one", "Invalid Entry", MessageBoxButtons.OK)


            End If
        Else
            MessageBox.Show("Letters are not an acceptible input within this application, please try again...enter a value greater than one.",
                            "Invalid Data", MessageBoxButtons.OK)
        End If



    End Sub

【问题讨论】:

  • 当您在调试器中单步执行此操作时,它具体在哪里失败?它在哪里表现与您的预期不同,发生这种情况时的运行时值是什么?
  • 消息框什么时候出现?更多细节请。
  • 看起来不错...只是没有在适当的时间出现。例如,它出现了,但在不应该更新 lblAmountEarnedResult 时仍然更新,因为出现了错误。

标签: .net vb.net visual-studio-2010


【解决方案1】:

显示消息框后需要退出子程序,尝试使用Exit Sub

If intDay < 19 Then
    MessageBox.Show("Error", "input error", MessageBoxButtons.OK)
    lblAmountEarnedResult.Text = ""
    Exit Sub
End If

【讨论】:

  • 成功了,非常感谢!在同一部分上进行了四天,在几分钟内你们就解决了哈哈。你是最棒的!
【解决方案2】:

改变

If intDay < 19 Then

If (intDay < 19 or intDay >22) then

【讨论】:

  • 也改。 If intDay > 0 Then To If (If (intDay 22) then
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-31
  • 2016-03-28
  • 1970-01-01
  • 1970-01-01
  • 2021-07-25
  • 2019-12-15
相关资源
最近更新 更多