Hi,
The following B4A code works fine in B4A but when I copy it and use it in B4i it fails.
The problem is with ToHexString
I then did a search and found: https://www.b4x.com/android/forum/threads/tohexstring.48215/#content
I then tried changing the code to be like the following:
However when I compile the app it comes up with:
I guess I am doing something wrong but can't work out how to fix this error..
Any ideas on how to fix this error?
The following B4A code works fine in B4A but when I copy it and use it in B4i it fails.
B4X:
Sub cmd1(value As String) As String
Try
Log(value)
Dim A As String
Dim Var2 As String
Dim Var4 As String
Dim Var5 As String
A=value.Length
'a = Hex(a + 2)
A=Bit.ToHexString(A+2)
A=A.ToUpperCase
'If Len(a) < 2 Then
If A.Length<2 Then
Var2 = "0" & A & value
Else
Var2 = A & value
End If
'a = Len(Var2)
A=Var2.Length
'Dim b As Integer
'Dim num As Integer
Dim b As Int
Dim num As Int
For b = 1 To A
'num=num+asc(Mid(Var2, b, 1)))
num = num + Asc(Var2.CharAt(b-1))
'Next b
Next
Var4 = num Mod 256
'Var5 = Hex(CByte(((Not Val(Var4)) + 1) AND 255))
Dim tempByte As Byte
tempByte=Bit.And ((Bit.Not(Var4)+1),255)
Var5 = Bit.ToHexString (tempByte)
Var5=Var5.SubString (Var5.Length -2)
'While Len(Var5) < 2
Do While Var5.Length < 2
Var5 = "0" & Var5
'Wend
Loop
'CalculateCRC = Var2 & Var5
Dim tempCRC As String
tempCRC=Var2 & Var5.Touppercase
Return tempCRC
Catch
Log(LastException.Message)
End Try
End Sub
The problem is with ToHexString
I then did a search and found: https://www.b4x.com/android/forum/threads/tohexstring.48215/#content
I then tried changing the code to be like the following:
B4X:
Sub cmd1(value As String) As String
Try
Log(value)
Dim A As String
Dim Var2 As String
Dim Var4 As String
Dim Var5 As String
Dim bc As ByteConverter
A=value.Length
'a = Hex(a + 2)
'A=Bit.ToHexString(A+2)
A = bc.HexFromBytes(Array As Byte(Bit.ParseInt(A+2, 2)))
A=A.ToUpperCase
'If Len(a) < 2 Then
If A.Length<2 Then
Var2 = "0" & A & value
Else
Var2 = A & value
End If
'a = Len(Var2)
A=Var2.Length
'Dim b As Integer
'Dim num As Integer
Dim b As Int
Dim num As Int
For b = 1 To A
'num=num+asc(Mid(Var2, b, 1)))
num = num + Asc(Var2.CharAt(b-1))
'Next b
Next
Var4 = num Mod 256
'Var5 = Hex(CByte(((Not Val(Var4)) + 1) AND 255))
Dim tempByte As Byte
tempByte=Bit.And ((Bit.Not(Var4)+1),255)
'Var5 = Bit.ToHexString (tempByte)
Var5 = bc.HexFromBytes(Array As Byte(Bit.ParseInt(tempByte, 2)))
Var5=Var5.SubString (Var5.Length -2)
'While Len(Var5) < 2
Do While Var5.Length < 2
Var5 = "0" & Var5
'Wend
Loop
'CalculateCRC = Var2 & Var5
Dim tempCRC As String
tempCRC=Var2 & Var5.Touppercase
Return tempCRC
Catch
Log(LastException.Description)
End Try
End Sub
However when I compile the app it comes up with:
B4i version: 2.31
Parsing code. (0.00s)
Compiling code. (0.21s)
Compiling layouts code. (0.00s)
Compiling debugger engine code. Error
B4i line: 64
For b = 1 To A
javac 1.8.0_60
shell\src\xxx\xxxxxx\test\b4i_main_subs_0.java:129: error: > expected
final int limit36 = BA.ObjectToNumber(_a.<NSString*>get()).intValue;
^
1 error
I guess I am doing something wrong but can't work out how to fix this error..
Any ideas on how to fix this error?