Stupid question number 4997.
Trying to get the sample B4JS code running. I am using the blog here.
What is happening is my app refuses to run with a call to the B4JS method included in the code. It just looks like this. Its stuck.
(last log entry is: Trying to open: http://localhost:51047/taskpro?1631356267976)
I add the call to one of my BTN events. If I REM out the call to B4JS it runs fine, if I leave it in it locks up like above and never runs.
B4JSClass - Copied from the Blog.
What am I missing?
Trying to get the sample B4JS code running. I am using the blog here.
B4X: ABMaterials B4JS – 01 Getting Started
In this first tutorial, we are going to create a killer method to calculate the distance between two GEO locations. There are better ways to do so, but for demos sake… Creating a B4JS class i…
alwaysbusycorner.com
What is happening is my app refuses to run with a call to the B4JS method included in the code. It just looks like this. Its stuck.
(last log entry is: Trying to open: http://localhost:51047/taskpro?1631356267976)
I add the call to one of my BTN events. If I REM out the call to B4JS it runs fine, if I leave it in it locks up like above and never runs.
B4JSClass - Copied from the Blog.
B4X:
'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
What am I missing?