试图编码(又称撕掉我的头发)

时间:2016-02-16 03:27:36

标签: visual-studio-2013 tryparse

我没有任何编码背景,所以我转向你们寻求帮助。我花了大约12个小时试图解决这个问题,使用我的学校书,微软网站,这个网站,几个朋友,我无法弄清楚代码有什么问题。是的,这是一个家庭作业问题,我不是要求你去做,我要求别人请你解释为什么它不起作用。

该项目背后的想法是: A)选择一个单选按钮,一个用于白天呼叫,一个是夜间呼叫,一个是非工作时间呼叫。 B)输入您谈话的分钟数,选择计算 C)魔术(数学)发生和战争,它给你数字。

如果选择无线电日,则费率为每分钟7美分,无线电之夜=每分钟12美分,无线电关闭时间=每分钟5美分。

所以,说到这里,按钮点击事件的代码,我尝试了很多不同的东西,它仍然导致答案是:$ 0.00

Private Sub btnCalc_Click(sender As Object, e As EventArgs) Handles btnCalc.Click
    Dim dblcharge2 As Double
    Dim dblmin As Double
    Dim blnInputOk As Boolean = True
    'give value to variables'

    If Double.TryParse(txtMin.Text, dblmin) And IsNumeric(txtMin.Text) And dblmin > 0 Then
        If radDay.Checked = True Then
            lblCharge2.Text = dblmin * 0.07
            lblCharge2.Text = dblcharge2.ToString("c")
        ElseIf radEve.Checked = True Then
            lblCharge2.Text = dblmin * 0.12
            lblCharge2.Text = dblcharge2.ToString("c")
        ElseIf radOff.Checked = True Then
            lblCharge2.Text = dblmin * 0.05
            lblCharge2.Text = dblcharge2.ToString("c")
        End If
    End If
    'Try Parse and calculate the number'
End Sub

1 个答案:

答案 0 :(得分:1)

这是因为你用“dblcharge2”设置标签。 请试试这个:

Private Sub btnCalc_Click(sender As Object, e As EventArgs) Handles btnCalc.Click
  Dim dblcharge2 As Double
  Dim dblmin As Double
  Dim blnInputOk As Boolean = True
  'give value to variables'

  If Double.TryParse(txtMin.Text, dblmin) And IsNumeric(txtMin.Text) And dblmin > 0 Then
    If radDay.Checked = True Then
        dblcharge2 = dblmin * 0.07
        lblCharge2.Text = dblcharge2.ToString("c")
    ElseIf radEve.Checked = True Then
        dblcharge2 = dblmin * 0.12
        lblCharge2.Text = dblcharge2.ToString("c")
    ElseIf radOff.Checked = True Then
        dblcharge2 = dblmin * 0.05
        lblCharge2.Text = dblcharge2.ToString("c")
    End If
  End If
  'Try Parse and calculate the number'
End Sub