0

したがって、このプログラムのタスクは、レンタカー会社向けのプログラムを作成することです。さまざまな種類の車をラジオ ボタンで選択し、レンタルする車の費用 (1 日あたり) にレンタルする日数を掛けます。私は本ですべてをやったので、何が悪いのですか?入力しているデータが数値ではないことを伝える、コーディングしたメッセージボックスが表示され続けます(数値です)

    Dim decJeepWrangler As Decimal = 55D
    Dim decLandRover As Decimal = 125D
    Dim decPickup As Decimal = 85D

    Dim intDays As Integer
    Dim decTotalCost As Decimal
    Dim decCost As Decimal

    If IsNumeric(txtDays) Then
        intDays = Convert.ToInt32(txtDays)

        If intDays > 0 Then
            If radJeepWrangler.Checked Then
                decCost = decJeepWrangler
            ElseIf radLandRover.Checked Then
                decCost = decLandRover
            ElseIf radPickup.Checked Then
                decCost = decPickup
            End If
            decTotalCost = intDays * decCost
            lblTotalCost.Text = decTotalCost.ToString("C")
        Else
            MsgBox("You entered " & intDays.ToString() & ". Enter a positive number", , "Input Error")
            txtDays.Text = ""
            txtDays.Focus()
        End If
    Else
        MsgBox("Enter how many days you will be renting", , "Input Error")
        txtDays.Text = ""
        txtDays.Focus()
    End If
End Sub
4

4 に答える 4

4

コメントするのに十分な評判ポイントがないので、これを回答として追加する必要がありましたが、開始するtxtDays代わりに使用しているようですtxtDays.Text.

于 2014-01-22T02:07:26.410 に答える
1

これがあなたがしなければならないことです...

1) Add a TextBox control and name it txtDays.
2) Add a button.
3) Add the code shown below under the button_click event.

    Dim decJeepWrangler As Decimal = 55D
    Dim decLandRover As Decimal = 125D
    Dim decPickup As Decimal = 85D

    Dim intDays As Integer
    Dim decTotalCost As Decimal
    Dim decCost As Decimal

    If IsNumeric(txtDays.Text) Then
        intDays = Convert.ToInt32(txtDays.Text)

        If intDays > 0 Then
            If radJeepWrangler.Checked Then
                decCost = decJeepWrangler
            ElseIf radLandRover.Checked Then
                decCost = decLandRover
            ElseIf radPickup.Checked Then
                decCost = decPickup
            End If
            decTotalCost = intDays * decCost
            lblTotalCost.Text = decTotalCost.ToString("C")
        Else
            MsgBox("You entered " & intDays.ToString() & ". Enter a positive number", , "Input Error")
            txtDays.Text = ""
            txtDays.Focus()
        End If
    Else
        MsgBox("Enter how many days you will be renting", , "Input Error")
        txtDays.Text = ""
        txtDays.Focus()
    End If
于 2014-01-22T02:27:24.680 に答える
0
Dim decJeepWrangler As Decimal = 55D
Dim decLandRover As Decimal = 125D
Dim decPickup As Decimal = 85D
Dim intDays As Integer = 0
Dim decTotalCost As Decimal = 0
Dim decCost As Decimal = 0
'
If Trim(txtDays.text) <> "" Then
    If cint(trim(txtDays.text)) > 0 Then
        intDays = CInt(txtDays.Text)
        If radJeepWrangler.Checked Then
            decCost = decJeepWrangler
        ElseIf radLandRover.Checked Then
            decCost = decLandRover
        ElseIf radPickup.Checked Then
            decCost = decPickup
        End if
        if decCost > 0 then
            decTotalCost = intDays * decCost
            lblTotalCost.Text = decTotalCost.ToString()
        Else
            msgbox("please select a vehicle", ,"Error")
            txtDays.Text = "0"
            txtDays.Focus()
        End If
    Else
        MsgBox("Enter how many days you will be renting", , "Error")
        txtDays.Text = "0"
        txtDays.Focus()
    End If
else
    MsgBox("Enter how many days you will be renting", , "Error")
    txtDays.Text = "0"
    txtDays.Focus()
end if

いくつかのエラーやタイプミスがすぐに飛び出しますが、上記のコードは問題なく動作するはずです。試してみてください。

于 2014-01-22T04:52:58.650 に答える
0

Macoms01が述べたように、 txtDays.Textを使用して TextBox から入力値を取得する必要があります。また、合計コストを計算する直前に decCost 変数を 0 に初期化して OR で開始し、decCost = null をチェックする IF ステートメントを記述し、その場合は 0 に設定する必要があります。

最後に、誰もがアドバイスに対して報酬を得ようとしているわけではないので、Neolisk の言うことを聞かないでください。私はここで、彼のように簡単な答えを求めている人に出会いました。彼らは、簡単な答えがあれば、人々は助けを求めてここに来ないだろうということを理解するのを忘れています.

いずれにせよ、私の回答が役に立った場合は、ここで他の誰かの質問に答えてください.

于 2014-01-22T02:34:48.340 に答える