Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim r, d As Double
        Const Pi = 3.141596
        r = Val(rtb.Text)
        d = Val(dtb.Text)
        If 0 < d < 360 Then
            r = d / 180 * Pi
            rtb.Text = Format(r, "0.00")
            dtb.Text = Format(d, "0.00")

        ElseIf 0 < r < Pi Then
            d = r / Pi * 180
            dtb.Text = Format(d, "0.00")
            rtb.Text = Format(r, "0.00")
        End If
    End Sub

Above is my code for my little converter for Radian-Degree or vice versa, and I'm only a newbie who still learning basics for Visual Basic.
My problem is, When I debug the program it seems like the code is only work when the degree is going to convert to radian but my radian cannot convert to degree. And when I reverse both arguments the radian in working to be converted to degree but degree is not going to be converted into radian.
I would like to know where is my problem, Thanks.

It's only doing one or the other because that's what you told it to do.

Study the code.

On line 6 you are saying if d is between 0 and 360 then calculate r

On line 11 with your elseif you are saying ...

if d isn't between 0 and 360 then check if r is between 0 and Pi calculate d

get ride of the Elseif

make it just an If

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim r, d As Double
        Const Pi = 3.141596
        Dim dblTempr as Double = Val(rtb.Text)
        Dim dblTempd as Double = Val(dtb.Text)
        If 0 < dblTempd < 360 Then
            r = dblTempd / 180 * Pi
            rtb.Text = Format(r, "0.00")
        End If
        If 0 < dblTempr < Pi Then
            d = dblTempr / Pi * 180
            dtb.Text = Format(d, "0.00")
        End If
    End Sub

But still you have logic problem if both text boxes are filled.

But you already know that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.