B4R Code Snippet Modulo Operator (Inline C)

Don't know for sure at 100% but haven't found Modulo Operator on B4R (strange as Arduino includes this operator)

So I attached how to calc Modulo between two numbers (does not work for Floats - https://www.arduino.cc/en/Reference/modulo) with Inline C

B4X:
Sub Process_Globals
    Public Serial1 As Serial
    Private Result, N1, N2 As ULong
    Public Timer1 As Timer
   
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    N1 = 100
    N2 = 10
    Timer1.Initialize("timer1_Tick",1000)
    Timer1.Enabled=True
End Sub

Sub Timer1_Tick
    N1=N1+1
    RunNative("Modulo", Null)
    Log("N1= ",N1," N2= ",N2," Result: ", Result )
End Sub

#if C
void Modulo (B4R::Object* o) {
   //lower case variables
   b4r_main::_result = b4r_main::_n1 % b4r_main::_n2;
}
#End if
 

inakigarm

Well-Known Member
Licensed User
Longtime User
The Modulo oprerator is Mod.
Which is the syntax? The B4R IDE doesn't accept Mod...

upload_2017-3-6_16-53-52.png
 

inakigarm

Well-Known Member
Licensed User
Longtime User
How do you expect Mod does work?
Result = 7 Mod 5
Result = 2.
Thanks Klaus, what was strange for me is that in B4R IDE this not appear as a valid 'keyword' nor on B4R documentation (even I've searched on the beginners guide)
 

Roycefer

Well-Known Member
Licensed User
Longtime User
The Mod operator is in the B4R autocomplete menu. It is just an illegal first word so it wasn't shown in your example. Type "5 Mo" and you will see Mod in the autocomplete menu.
 
Top