B4J Question [ABMaterial] Calling B4JS functions stops App.

JakeBullet70

Well-Known Member
Licensed User
Longtime User
Stupid question number 4997. o_O

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)
1631356306147.png

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.
1631357494889.png


1631357780658.png

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?
 

Attachments

  • 1631356409987.png
    1631356409987.png
    26.1 KB · Views: 216

OliverA

Expert
Licensed User
Longtime User
Upvote 0

JakeBullet70

Well-Known Member
Licensed User
Longtime User
Upvote 0

JakeBullet70

Well-Known Member
Licensed User
Longtime User
The work around was to edit the offending.ja file and change the : to =
Note: Have to do this every time the file is regenerated
I am seeing the 'swaloptions.rtl:' too although I have no files missing.

Did you automate the editing of the output file when regenerated? I am not sure how to change it.
Learning more about web crap then I ever wanted too... lol
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Upvote 0
Top