Option Explicit
Function Deg2Rad(Deg) As Double
Deg2Rad = Deg / 57.2957795130823
End Function
Function Rad2Deg(Rad) As Double
Rad2Deg = 57.2957795130823 * Rad
End Function
Sub DegRad_Test()
Dim Ans As String
Dim I As Integer
Dim Title As String
Dim X As Single
Title = "Test of degree < > radian conversion functions"
GetInitial:
Ans = InputBox("enter test #:" & vbCrLf & _
"1 convert from degrees to radians" & vbCrLf & _
"2 convert from radians to degrees" & vbCrLf & _
"[enter nothing or click on Cancel to quit]", Title)
If Ans = "" Then Exit Sub
I = Ans
Select Case I
Case Is = 1
GetCase1: Ans = InputBox("value in degrees ?", "Demo of Deg2Rad")
If Ans = "" Then GoTo GetInitial
X = Ans
MsgBox X & " degrees = " & Format(Deg2Rad(X), "##0.###") & " radians", _
vbInformation, Title
GoTo GetCase1
Case Is = 2
GetCase2: Ans = InputBox("value in radians ?", "Demo of Rad2Deg")
If Ans = "" Then GoTo GetInitial
X = Ans
MsgBox X & " radians = " & Format(Rad2Deg(X), "##0.###") & " degrees", _
vbInformation, Title
GoTo GetCase2
End Select
GoTo GetInitial
End Sub
|