iOS Question B4i Error related to substring2

Nitin Joshi

Active Member
Licensed User
Hi, i am using following code however error message pops up when i run the program.
Substring2 code:
For i= UDPRcvMsg.SubString2(28,31) To UDPRcvMsg.SubString2(31,34)

Error message...
For i= UDPRcvMsg.SubString2(28,31) To UDPRcvMs
shell\src\b4i\example2\b4i_b4xmainpage_subs_0.java:570: error: > or ',' expected
final int limit16 = BA.ObjectToNumber(__ref.getField(true,"_udprcvmsg" /*RemoteObject*/ ).runMethod(true,"SubString2::",(Object)(BA.numberCast(int.class, 31)),(Object)(BA.numberCast(int.class, 34))).<NSString*>get()).intValue;
 
Solution
I have not tested your code. It could work under B4A because B4A may convert the strings automatically to integers. However, you should definitely see a warning: You are using a string as an integer, this may be a programming error.

BlueVision

Well-Known Member
Licensed User
Longtime User
I'm not using B4I, but you are using strings as variables for the for-next loop in this case. I think this is causing the error.
Convert the substrings to integer variables before using them...
You must also ensure that the substrings only contain digits.
B4X:
Dim a = UDPRcvMsg.SubString2(28,31) as Int
Dim b = UDPRcvMsg.SubString2(31,34) as Int
For i = a To b
 
Last edited:
Upvote 0

BlueVision

Well-Known Member
Licensed User
Longtime User
I have not tested your code. It could work under B4A because B4A may convert the strings automatically to integers. However, you should definitely see a warning: You are using a string as an integer, this may be a programming error.
 
Upvote 0
Solution

Nitin Joshi

Active Member
Licensed User
Thanks dear. You are right. In For-Next loop string can not be considered as int. Meanwhile, i had to modify code as below...

Code:
Dim k1,k2 As Int
k1 = UDPRcvMsg.SubString2(28,31)
k2 = UDPRcvMsg.SubString2(31,34)
for i = k1 to k2
 
Upvote 0
Top