0

So for this program the task is to create a program for a car rental company. The different kinds of cars are chosen by radio buttons and the cost of the car to rent (per day) is multiplied by the days it will be rented. I've done everything by the books so what's wrong? It keeps coming up with the Message Box I coded telling me that the data I'm entering is not numeric (which it is)

    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
  • Please describe exactly what is wrong with your code. We won't be doing the guess work, this is what contractors are usually for, and they charge big for that. – Victor Zakharov Jan 22 '14 at 01:54
  • 3
    The declaration of `txtDays` isn't included in your post. What is it? Is it actually **text**. Oh, wait! No, because you call its `.Focus()` method, and a string doesn't *have a .Focus()* event. You should actually **read the code**. (The debugger would also tell you this; you should learn to use it now.) – Ken White Jan 22 '14 at 02:01
  • txtDays is a text box if one goes by naming conventions – Zeddy Jan 22 '14 at 04:55

4 Answers4

4

I don't have enough reputation points to comment so I had to add this as an answer, but it looks like you are using txtDays instead of txtDays.Text to start.

macoms01
  • 1,110
  • 13
  • 22
1

Here's what you'll have to do...

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
chris_techno25
  • 2,401
  • 5
  • 20
  • 32
0

Just like Macoms01 mentioned you need to use txtDays.Text to retrieve the input value from the TextBox. Also, you need to initialize decCost variable to 0 to start with OR right before you calculate the total cost, write an IF statement to check for decCost = null and set to 0 if that's the case.

Lastly, not everyone is looking to get paid for their advice so don't listen to Neolisk. I have encountered others like him here who just look to provide an easy answer. They forget to understand that if there was an easy answer, people wouldn't be here looking for help.

In any case, if my response was of any help to you, please answer a question for someone else on here.

Imad S.
  • 375
  • 3
  • 15
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

a few errors or typos jump out straight away, the code above should work fine, please try it and see.

Zeddy
  • 2,079
  • 1
  • 15
  • 23