iOS Question Modulo Expression Won't Compile

Jim McDougal

Member
Licensed User
I'm converting a B4A app to B4i and I'm getting this compile error:

B4i Version: 8.51
Parsing code. (0.08s)
Building folders structure. (0.00s)
Compiling code. Error
Error compiling program.
Error description: Integer expected.
Error occurred on line: 2272
If Main.CompHand.Get(N) Mod 13 = Kay Mod 13 Then KCount = KCount + 1
Word: mod

B4X:
    For N = 0 To Main.CompHand.Size - 1
        If Main.CompHand.Get(N) < 53 Then
            If Main.CompHand.Get(N) Mod 13 = Kay Mod 13 Then KCount = KCount + 1
        End If
    Next

All of the variables here are INT.
 

Jim McDougal

Member
Licensed User
Most unfortunate. A solution, but not a happy one.

B4X:
    For N = 0 To Main.CompHand.Size - 1
        If Main.CompHand.Get(N) < 53 Then
            Dim CH As Int
            CH = Main.CompHand.Get(N)
            If CH Mod 13 = Kay Mod 13 Then KCount = KCount + 1
        End If
    Next

Many Mod statements like this to attend to check in my app, but I guess I have my answer. :mad:
 
Upvote 0

emexes

Expert
Licensed User
I love Mod too, but usually put it inside brackets, so maybe that's why I've never encountered that compile error.

B4X:
For N = 0 To Main.CompHand.Size - 1
    If Main.CompHand.Get(N) < 53 Then
        If (Main.CompHand.Get(N) Mod 13) = (Kay Mod 13) Then KCount = KCount + 1
    End If
Next

Not tested due B4I not installed on this laptop, but I'd be interested to know if brackets fixes the problem.

PowerBasic has a similar quirk with boolean operators (not that it matters, other than it's nice to know it's not just you when strange stuff happens ?)
 
Upvote 0

emexes

Expert
Licensed User
I just noticed you're calling Main.CompHand.Get(N) twice, so perhaps your temporary variable CH isn't such a bad idea anyway ? eg:

B4X:
For N = 0 To Main.CompHand.Size - 1
    Dim CH As Int = Main.CompHand.Get(N)
    If CH < 53 Then
        If CH Mod 13 = Kay Mod 13 Then KCount = KCount + 1
    End If
Next
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
When you get an item from a list, the compiler does not know what type you mean to cast it to.
- so use Main.CompHand.Get(N).As(Int) Mod 13
 
Upvote 0

emexes

Expert
Licensed User
@William Lancee snuck in the probably-correct answer whilst I was writing this post, but I'll leave it here anyway, just in case ? :


Bracketing the List Get expression didn't have any effect.

Well, that feels odd.

In B4A your original post code compiles to:
Java:
int _n = 0;
final int step1 = 1;
final int limit1 = (int) (mostCurrent._main._comphand /*anywheresoftware.b4a.objects.collections.List*/ .getSize()-1);
_n = (int) (0) ;
for (;_n <= limit1 ;_n = _n + step1 ) {
if ((double)(BA.ObjectToNumber(mostCurrent._main._comphand /*anywheresoftware.b4a.objects.collections.List*/ .Get(_n)))<53) {
if ((double)(BA.ObjectToNumber(mostCurrent._main._comphand /*anywheresoftware.b4a.objects.collections.List*/ .Get(_n)))%13==_kay%13) {
_kcount = (int) (_kcount+1);};
 };
 }
};

If you're keen, see if you can find the corresponding Onjective C output from B4I.
 
Last edited:
Upvote 0
Top