B4X:
#Region Project Attributes
#ApplicationLabel: Radians/Degree Calculator
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim radresultnum As Label
Dim radresultden As Label
Dim radval As Int
Dim label5 As Label
Dim label4 As Label
Dim radbox As EditText
Dim radbox2 As EditText
Dim degvalinput As EditText
Dim WebView1 As WebView
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
Activity.LoadLayout("Layout1")
Activity.AddMenuItem("Email Developer","Email")
Activity.AddMenuItem("Share App Via Facebook","Share")
Activity.AddMenuItem("About","change")
End Sub
Sub email_click
Dim Message As Email
Message.To.Add("")
StartActivity(Message.GetIntent)
End Sub
Sub change_click
StartActivity(layout2)
End Sub
Sub share_click
Dim Intent1 As Intent
Intent1.Initialize2("http://www.facebook.com/sharer.php?u=http://www.google.com", 0)
StartActivity(Intent1)
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Activity_Resume
End Sub
Sub Button1_Click
Try
Dim degressvalend As Float
degressvalend = (radbox.Text*180)/radbox2.Text
label5.text = degressvalend & "°"
Catch
Msgbox ("You forgot to enter a value or you've entered something that is not a number.","Error")
End Try
End Sub
Sub Button2_Click
Dim DEG As Float
DEG = degvalinput.Text
label4.Text = (DEG*0.01745) & " Radians"
' Get the initial denominator: 1 * (10 ^ decimal portion length)
Dim denom As Int = 180
' Get the initial numerator: integer portion of the number
Dim numer As Int = degvalinput.Text
' Use the Euclidean algorithm to find the gcd
Dim a As Int = degvalinput.Text
Dim b As Int = 180
Dim t As Int = 0 ' t is a value holder
' Euclidean algorithm
Do While b <> 0
t = b
b = a Mod b
a = t
Loop
'Get whole part of the number
Dim Whole As String
' Return our answer
Dim numerfinal As Int
Dim demonfinal As Int
numerfinal = (numer / a)
demonfinal = (denom / a)
Dim radresultnum As Label
Dim radresultden As Label
radresultnum.Text = numerfinal
radresultden.Text = demonfinal
Dim label8 As Label
label8.Text = t
End Sub
My code is above and when I actually run the program the labels I get an error saying the object must first be initialized. (the process is under "Sub Button2_Click")
Last edited: