'Class module
Sub Class_Globals
' use public or dim if you want to share this variable over ALL B4JS classes
' use private if only within this class
Dim ToKM As Double = 1.609344
Dim ToMiles As Double = 0.8684
' to access the constants
Public ABM As ABMaterial 'ignore
' so we can use an msgbox
Public Page As ABMPage 'ignore, just to be able to run ABMPage functions
End Sub
'Initializes the object. You can NOT add parameters to this method.
'MUST be called InitializeB4JS is automatically called when using this class
Public Sub InitializeB4JS
'Page.B4JSRunMethod("B4JSCalculateDistance", "CalcDistance", Array As Object(32.9697, -96.80322, 29.46786, -98.53506, "K"))
End Sub
public Sub CalcDistance(Lat1 As Double, Lon1 As Double, Lat2 As Double, Lon2 As Double, Unit As String)
Dim theta As Double
Dim Distance As Double
theta = Lon1 - Lon2
Distance = Sin(deg2rad(Lat1)) * Sin(deg2rad(Lat2)) + Cos(deg2rad(Lat1)) * Cos(deg2rad(Lat2)) * Cos(deg2rad(theta))
' logging some intermediate value
Log("Distance = " & Distance)
Distance = ACos(Distance)
Distance = rad2deg(Distance)
' logging some intermediate value
Log("Distance = " & Distance)
Distance = Distance * 60 * 1.1515
' if we would use Page.Msgbox here, we would see in the logs an error: msgbox is NOT supported in B4JS!
' we must use the B4JS equivalent method Page.B4JSMsgbox
Select Case Unit.ToUpperCase
Case "K"
Page.B4JSMsgbox("msgbox", "The distance is " & (Distance * ToKM) & " kilometers!", "Tutorial", "OK", False, ABM.MSGBOX_POS_CENTER_CENTER, "")
Case "N"
Page.B4JSMsgbox("msgbox", "The distance is " & (Distance * ToMiles) & " miles!", "Tutorial", "OK", False, ABM.MSGBOX_POS_CENTER_CENTER, "")
Case Else
Page.B4JSMsgbox("msgbox", "No idea what you are doing :-)", "Tutorial", "OK", False, ABM.MSGBOX_POS_CENTER_CENTER, "")
End Select
End Sub
' some helper methods
Sub deg2rad(Deg As Double) As Double
Return Deg * cPI / 180
End Sub
Sub rad2deg(Rad As Double) As Double
Return Rad * 180 / cPI
End Sub
'#if JAVASCRIPT
'
'#End If