iOS Question B4A to B4I

iCAB

Well-Known Member
Licensed User
Longtime User
Hi there
Is there a list that shows which libraries or type of code can be reused/shared between a B4A and B4I projects.

Thank you
 
Upvote 0

iCAB

Well-Known Member
Licensed User
Longtime User
Can someone tell me why does this code generate an error when compiled using B4A

B4X:
If IsDevTool("B4A") Then
    Dim pLocalPhone As Phone
    pLocalPhone.HideKeyboard(Activity)
Else
        'Why does this generate an error when compiled using B4A. Isn't IsDevTool equivalent to conditional compile
    Garbage text
End If
 
Upvote 0

stanmiller

Active Member
Licensed User
Longtime User
Can someone tell me why does this code generate an error when compiled using B4A

B4X:
If IsDevTool("B4A") Then
    Dim pLocalPhone As Phone
    pLocalPhone.HideKeyboard(Activity)
Else
        'Why does this generate an error when compiled using B4A. Isn't IsDevTool equivalent to conditional compile
    Garbage text
End If

I expect that IsDevTool() is evaluated at runtime such that a common library (precompiled) could be shared between platforms. Thus the entire If/Then statement should be valid.
 
Upvote 0

iCAB

Well-Known Member
Licensed User
Longtime User
Mod Operation B4A vs B4i.
Not sure If I am doing something wrong, but to my understanding this should work

B4X:
Sub Test()
    Dim TimeComponents(2) As String
  
    TimeComponents(0) = "0"
    TimeComponents(1) = "1"
    TimeComponents(2) = "2"
  
        'This compiles with b4A, doesn't generates an error with B4i
    TimeComponents(0) = TimeComponents(0) Mod 12

        'This code compiles with Both
    Dim iComponent0 As Int = TimeComponents(0)
    iComponent0 = iComponent0 Mod 12
  

End Sub
 
Upvote 0

stanmiller

Active Member
Licensed User
Longtime User
Mod Operation B4A vs B4i.
Not sure If I am doing something wrong, but to my understanding this should work

B4A and B4i will automatically convert strings to numbers. And while this is convenient and useful at times, it's not necessarily best practice.

Modulus is an arithmetic operation and TimeComponents is an array of strings. (Separate from the math issue, your array is 2 elements but you have attempted to assign three items.)

The Java output underlying B4A is probably more forgiving than the ObjectiveC generated by B4i. Thus ObjectiveC complains where Java will let it ride.

The reason the second block of code works is because TimeComponents(0) is explicity converted to an Int when stored in iComponent0. And no math conflict computing modulus on a number.
 
Upvote 0

iCAB

Well-Known Member
Licensed User
Longtime User
Hi Stanmiller

Thanks for your reply.
Yes I can see how the array size is 2 and I assigned 3 elements. I didn't check the code as this is not the real code extracted from the project. I just typed couple of lines to show the issue without even checking, but thanks for bringing it up.

Yes, I do agree with everything you are saying. However the reason behind the original code is the following:
I am parsing a string such as "23:02:03" and later on trying to check if all elements are numbers (instead of trying to parse to an int array which most likely is not the best way of doing it ), followed by the Mod operation to convert a 24 hour time string to AM/PM.

The reason the second block of code works is because TimeComponents(0) is explicity converted to an Int when stored in iComponent0. And no math conflict computing modulus on a number.
That was also obvious in the above and that's why I tried that code to make sure that was the case.
But I thought I will bring the issue up for more compatibility between B4A and B4i codes.

Thanks again for your input
 
Upvote 0
Top