francoisg Active Member Licensed User Longtime User Jul 20, 2011 #1 Hi, in the following code I am defining a byte array - afterwards I want to check if it has been set or not by checking if it is null ... Dim data() As Byte .... If data = Null Then ExitApplication When I try to compile I get the following: Compiling generated Java code. Error B4A line: 92 If data = Null Then ExitApplication javac 1.6.0_24 src\hawkstone\epod\actprocessdoc.java:323: incomparable types: byte[] and double if (_data==(double)(BA.ObjectToNumber(anywheresoftware.b4a.keywords.Common.Null))) { ^ Obviously I cannot check the length as the variable value is actually null. Is there another / better way of checking if arrays has been assigned values ???
Hi, in the following code I am defining a byte array - afterwards I want to check if it has been set or not by checking if it is null ... Dim data() As Byte .... If data = Null Then ExitApplication When I try to compile I get the following: Compiling generated Java code. Error B4A line: 92 If data = Null Then ExitApplication javac 1.6.0_24 src\hawkstone\epod\actprocessdoc.java:323: incomparable types: byte[] and double if (_data==(double)(BA.ObjectToNumber(anywheresoftware.b4a.keywords.Common.Null))) { ^ Obviously I cannot check the length as the variable value is actually null. Is there another / better way of checking if arrays has been assigned values ???
agraham Expert Licensed User Longtime User Jul 20, 2011 #2 francoisg said: Obviously I cannot check the length Click to expand... Actually you can. Basic4android will never leave a variable uninitialised so it is quite safe to check the length. In your case it will return zero as Dim a() and Dim a(0) are the same.
francoisg said: Obviously I cannot check the length Click to expand... Actually you can. Basic4android will never leave a variable uninitialised so it is quite safe to check the length. In your case it will return zero as Dim a() and Dim a(0) are the same.
francoisg Active Member Licensed User Longtime User Jul 20, 2011 #3 mmm.. then I am doing something wrong - "Log(Data.Length)" gives a null pointer exception ...
agraham Expert Licensed User Longtime User Jul 20, 2011 #4 I did check, and look at the generated code, before I posted as I always try to do but just to be sure I checked again. Code: Dim anarray() As Byte Log(anarray.Length) ToastMessageShow(anarray.Length,True) Works fine!
I did check, and look at the generated code, before I posted as I always try to do but just to be sure I checked again. Code: Dim anarray() As Byte Log(anarray.Length) ToastMessageShow(anarray.Length,True) Works fine!
Erel B4X founder Staff member Licensed User Longtime User Jul 20, 2011 #5 How are you assigning the value to Data?
francoisg Active Member Licensed User Longtime User Jul 20, 2011 #6 I am getting it from the camera - if the user decides not to use the image, the data variable is null ... One thing, the data array is part of a type defined in a code module, might this maybe have an effect at all (type abc (data() as byte, ...) ???
I am getting it from the camera - if the user decides not to use the image, the data variable is null ... One thing, the data array is part of a type defined in a code module, might this maybe have an effect at all (type abc (data() as byte, ...) ???
francoisg Active Member Licensed User Longtime User Jul 20, 2011 #7 It seems we both are correct ;-) Local variables are assigned, global variables that is a "type" variable does not seem to be initialized ... maybe I am using it wrong, will have to experiment a bit and see ...
It seems we both are correct ;-) Local variables are assigned, global variables that is a "type" variable does not seem to be initialized ... maybe I am using it wrong, will have to experiment a bit and see ...
agraham Expert Licensed User Longtime User Jul 20, 2011 #8 I misunderstood what you meant by set, I assumed ReDimmed. You can use a Reflector Object as a workaround. Code: Dim ba() As Byte ... Dim Obj1 As Reflector Obj1.Target = ba If Obj1.Target = Null Then ' or If Obj1.IsNull Then ToastMessageShow("Null",True) Else ToastMessageShow(Obj1.Target,True) End If
I misunderstood what you meant by set, I assumed ReDimmed. You can use a Reflector Object as a workaround. Code: Dim ba() As Byte ... Dim Obj1 As Reflector Obj1.Target = ba If Obj1.Target = Null Then ' or If Obj1.IsNull Then ToastMessageShow("Null",True) Else ToastMessageShow(Obj1.Target,True) End If
agraham Expert Licensed User Longtime User Jul 20, 2011 #9 francoisg said: variables that is a "type" variable does not seem to be initialized Click to expand... It was initialised but you assigned null to it and lost the original zero length array. EDIT:- Assuming that you did call Initialize on it like you should with all "type" variables. Last edited: Jul 20, 2011
francoisg said: variables that is a "type" variable does not seem to be initialized Click to expand... It was initialised but you assigned null to it and lost the original zero length array. EDIT:- Assuming that you did call Initialize on it like you should with all "type" variables.
Erel B4X founder Staff member Licensed User Longtime User Jul 20, 2011 #10 Once you assign the value from the camera then the previous value is discarded. So if the camera returns null then you will get a null array. Your checking code is correct. It seems like a bug in the compiler. The workaround is to explicitly convert the array to an object: Code: Dim o As Object o = Data If o = Null then ... 'continue working with Data
Once you assign the value from the camera then the previous value is discarded. So if the camera returns null then you will get a null array. Your checking code is correct. It seems like a bug in the compiler. The workaround is to explicitly convert the array to an object: Code: Dim o As Object o = Data If o = Null then ... 'continue working with Data
agraham Expert Licensed User Longtime User Jul 20, 2011 #11 :sign0161: I forgot Basic4android supported "Object" as a type - still prone to thinking in B4P terms on occasion! Getting older and older ...
:sign0161: I forgot Basic4android supported "Object" as a type - still prone to thinking in B4P terms on occasion! Getting older and older ...
francoisg Active Member Licensed User Longtime User Jul 20, 2011 #12 Erels's solutions seems to work - thanx for the workaround!!