Hello, I've been trying to create a function to calculate and return the total payment. RadioDay is a radio button with value of 7 while RadioHour is 70. Somehow I am getting InvalidCastException "Conversion from string "" to type 'Integer' is not valid." from the part where I want to convert user inputs from textbox "txtByHour" and "txtByDay" into integer value. Any help is greatly appreciated.

Function calcRate() As Integer 'calculate and return total payment for car
        Dim total, byHour, byDay As Integer

        byHour = CInt(txtByHour.Text)
        byDay = CInt(txtByDay.Text)

        If byHour > 24 Then 'making sure the user does not input more than 24 hours
            MessageBox.Show("Please put a number between 1 to 24")
        End If

        If RadioDay.Checked Then

            total = byHour * 7
        ElseIf RadioHour.Checked Then

            total = byDay * 70
        End If


        Return total


    End Function

Maybe use this:

        byHour = CInt(Val(Trim(txtByhour.Text)))
        byDay = CInt(Val(Trim(txtByday.Text)))
commented: It works +0

Thank you very much it's working perfectly now

Thank you all , I just learnt something new today =)