C Christian75 Member Dec 2, 2022 #1 Hi, Is it possible to make this in BANano B4j: JavaScript: Copy const arr1 = ["Cecilie", "Lone"]; const arr2 = [1, 2, 3]; const arr3 = arr1.concat(arr2); I tried something like this: B4X: Copy Private hidden() As String = Array As String("one", "two", "three") Private shown() As String = Array As String("four", "five", "six") Private all() As String = Array As String(hidden(), shown()) But the above does not work. Or is the only option to merge them in a function at init?
Hi, Is it possible to make this in BANano B4j: JavaScript: Copy const arr1 = ["Cecilie", "Lone"]; const arr2 = [1, 2, 3]; const arr3 = arr1.concat(arr2); I tried something like this: B4X: Copy Private hidden() As String = Array As String("one", "two", "three") Private shown() As String = Array As String("four", "five", "six") Private all() As String = Array As String(hidden(), shown()) But the above does not work. Or is the only option to merge them in a function at init?
angel_ Well-Known Member Licensed User Longtime User Dec 2, 2022 #2 Try this: B4X: Copy Private all() As String = BANano.Concat(arr1, arr2) Upvote 0 Solution
C Christian75 Member Dec 3, 2022 #3 angel_ said: Try this: B4X: Copy Private all() As String = BANano.Concat(arr1, arr2) Click to expand... Ok thanks, I guess this should work but for me the transpiled version looks like this: JavaScript: Copy this.all = this.arr1.concat(_B.arr2); And _B is not defined until initialize where _B = this; So I get an error that arr2 is undefined. I changed _B. by hand to this. after transpiled then it works so I guess it might be a bug in the transpiler. Last edited: Dec 3, 2022 Upvote 0
angel_ said: Try this: B4X: Copy Private all() As String = BANano.Concat(arr1, arr2) Click to expand... Ok thanks, I guess this should work but for me the transpiled version looks like this: JavaScript: Copy this.all = this.arr1.concat(_B.arr2); And _B is not defined until initialize where _B = this; So I get an error that arr2 is undefined. I changed _B. by hand to this. after transpiled then it works so I guess it might be a bug in the transpiler.
C Christian75 Member Dec 19, 2022 #4 @alwaysbusy can yo take a look at this? Kind of not so much fun to change it manually every time I build. The transpiler should make this code to make it work: JavaScript: Copy this.all = this.arr1.concat(this.arr2); Instead of the wrong one I mention in previous reply with _B.arr2. Upvote 0
@alwaysbusy can yo take a look at this? Kind of not so much fun to change it manually every time I build. The transpiler should make this code to make it work: JavaScript: Copy this.all = this.arr1.concat(this.arr2); Instead of the wrong one I mention in previous reply with _B.arr2.
alwaysbusy Expert Licensed User Longtime User Dec 19, 2022 #5 I need a runnable example to find out what goes wrong in your code. Works fine here: Code: Copy Sub BANano_Ready() Dim arr1() As String = Array(1,2,3) Dim arr2() As String = Array(4,5,6) Dim all() As String = BANano.Concat(arr1, arr2) Log(all) ' [1,2,3,4,5,6] End Sub The only way I can reproduce something like yours is because you would put all of it in the Globals method, which is just for declaration in B4J. Code: Copy Sub Process_Globals Dim arr1() As String = Array(1,2,3) Dim arr2() As String = Array(4,5,6) Dim all() As String = BANano.Concat(arr1, arr2) End Sub But this is would be wrong as the IDE even shows in the logs: Main - 14: This sub should only be used for variables declaration or assignments of primitive values. (warning #29) Alwaysbusy Upvote 0
I need a runnable example to find out what goes wrong in your code. Works fine here: Code: Copy Sub BANano_Ready() Dim arr1() As String = Array(1,2,3) Dim arr2() As String = Array(4,5,6) Dim all() As String = BANano.Concat(arr1, arr2) Log(all) ' [1,2,3,4,5,6] End Sub The only way I can reproduce something like yours is because you would put all of it in the Globals method, which is just for declaration in B4J. Code: Copy Sub Process_Globals Dim arr1() As String = Array(1,2,3) Dim arr2() As String = Array(4,5,6) Dim all() As String = BANano.Concat(arr1, arr2) End Sub But this is would be wrong as the IDE even shows in the logs: Main - 14: This sub should only be used for variables declaration or assignments of primitive values. (warning #29) Alwaysbusy
C Christian75 Member Dec 19, 2022 #6 alwaysbusy said: I need a runnable example to find out what goes wrong in your code. Works fine here: Code: Copy Sub BANano_Ready() Dim arr1() As String = Array(1,2,3) Dim arr2() As String = Array(4,5,6) Dim all() As String = BANano.Concat(arr1, arr2) Log(all) ' [1,2,3,4,5,6] End Sub The only way I can reproduce something like yours is because you would put all of it in the Globals method, which is just for declaration in B4J. Code: Copy Sub Process_Globals Dim arr1() As String = Array(1,2,3) Dim arr2() As String = Array(4,5,6) Dim all() As String = BANano.Concat(arr1, arr2) End Sub But this is would be wrong as the IDE even shows in the logs: Main - 14: This sub should only be used for variables declaration or assignments of primitive values. (warning #29) Alwaysbusy Click to expand... Ok, then it is my fault. I missed that warning. I have it in the Process_Globals but it works if it has "this" instead of _B and if I look in Javascript descriptions then I do not find that limitation. But what I want to do is have two separate arrays concatenated to one, see first question in this thread. I need to use the two arrays separately and them both together and concat works as I want but maybe you have a better solution? Best regards Christian Upvote 0
alwaysbusy said: I need a runnable example to find out what goes wrong in your code. Works fine here: Code: Copy Sub BANano_Ready() Dim arr1() As String = Array(1,2,3) Dim arr2() As String = Array(4,5,6) Dim all() As String = BANano.Concat(arr1, arr2) Log(all) ' [1,2,3,4,5,6] End Sub The only way I can reproduce something like yours is because you would put all of it in the Globals method, which is just for declaration in B4J. Code: Copy Sub Process_Globals Dim arr1() As String = Array(1,2,3) Dim arr2() As String = Array(4,5,6) Dim all() As String = BANano.Concat(arr1, arr2) End Sub But this is would be wrong as the IDE even shows in the logs: Main - 14: This sub should only be used for variables declaration or assignments of primitive values. (warning #29) Alwaysbusy Click to expand... Ok, then it is my fault. I missed that warning. I have it in the Process_Globals but it works if it has "this" instead of _B and if I look in Javascript descriptions then I do not find that limitation. But what I want to do is have two separate arrays concatenated to one, see first question in this thread. I need to use the two arrays separately and them both together and concat works as I want but maybe you have a better solution? Best regards Christian
alwaysbusy Expert Licensed User Longtime User Dec 20, 2022 #7 Christian75 said: if I look in Javascript descriptions then I do not find that limitation Click to expand... True, but it is a B4J one. I honestly don't see the problem why you can not just concat them in the initialize of the class (or write one if it is a module and run it in BANano_Ready). Beats having to that manual change every time you do a build to me. As in B4J, BANano uses Global only for declarations and primitive initializations. There are many things that can be done in JavaScript and not in B4J, but we've chosen to get as close as possible to B4X behavior as possible. Upvote 0
Christian75 said: if I look in Javascript descriptions then I do not find that limitation Click to expand... True, but it is a B4J one. I honestly don't see the problem why you can not just concat them in the initialize of the class (or write one if it is a module and run it in BANano_Ready). Beats having to that manual change every time you do a build to me. As in B4J, BANano uses Global only for declarations and primitive initializations. There are many things that can be done in JavaScript and not in B4J, but we've chosen to get as close as possible to B4X behavior as possible.
C Christian75 Member Dec 20, 2022 #8 alwaysbusy said: True, but it is a B4J one. I honestly don't see the problem why you can not just concat them in the initialize of the class (or write one if it is a module and run it in BANano_Ready). Beats having to that manual change every time you do a build to me. As in B4J, BANano uses Global only for declarations and primitive initializations. There are many things that can be done in JavaScript and not in B4J, but we've chosen to get as close as possible to B4X behavior as possible. Click to expand... Ok, thank you for the help! Upvote 0
alwaysbusy said: True, but it is a B4J one. I honestly don't see the problem why you can not just concat them in the initialize of the class (or write one if it is a module and run it in BANano_Ready). Beats having to that manual change every time you do a build to me. As in B4J, BANano uses Global only for declarations and primitive initializations. There are many things that can be done in JavaScript and not in B4J, but we've chosen to get as close as possible to B4X behavior as possible. Click to expand... Ok, thank you for the help!
alwaysbusy Expert Licensed User Longtime User Dec 20, 2022 #9 I see what I can do for a next release, but I strongly advice still to use the 'normal' B4J behavior. Upvote 0
I see what I can do for a next release, but I strongly advice still to use the 'normal' B4J behavior.
C Christian75 Member Dec 20, 2022 #10 I moved the concat to init as you suggested and it works as it should. Once more thank you for the help! Upvote 0
I moved the concat to init as you suggested and it works as it should. Once more thank you for the help!