# Moving data between Arrays

**URL:** <https://forum.xojo.com/t/moving-data-between-arrays/29069>\
**Category:** Getting Started\
**Created:** [January 7, 2016, 6:27pm UTC](https://forum.xojo.com/t/moving-data-between-arrays/29069 "2016-01-07T18:27:35Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Armando\_SORBI](https://forum.xojo.com/user_avatar/forum.xojo.com/armando_sorbi/32/934_2.png) [@Armando\_SORBI](https://forum.xojo.com/u/Armando_SORBI)\
**Post date:** [January 7, 2016, 6:27pm UTC](https://forum.xojo.com/t/moving-data-between-arrays/29069/1 "2016-01-07T18:27:35Z")

</div>

Now, I have an array which collects numbers (as strings) thru the Split function, comma separated.  
I’m trying to convert them to numerals by the “val” function and fill another array.  
Dim Arr() as string  
Dim Nnn(), i as integer  
s=TextField1.text

Arr=s.Split(",")

For i=0 to 10  
Nnn(i)=val(Arr(i))  
Next

Doing this I get an “OutOfBoundsException” error and I don’t know why.  
I get the same error even if I give a fixed dimension to the arrays (say Arr(10) and Nnn(10)).

Any help?  
Thank you

---

<div class="post-metadata">

**Author:** ![Norman\_P](https://forum.xojo.com/letter_avatar_proxy/v4/letter/n/858c86/32.png) [@Norman\_P](https://forum.xojo.com/u/Norman_P)\
**Post date:** [January 7, 2016, 6:29pm UTC](https://forum.xojo.com/t/moving-data-between-arrays/29069/2 "2016-01-07T18:29:28Z")

</div>

nnn has no elements  
its empty

so assigning nnn(i) is trying to access an element that does not exist - hence out of bounds

try  
Nnn.append val(Arr(i))

---

<div class="post-metadata">

**Author:** ![Armando\_SORBI](https://forum.xojo.com/user_avatar/forum.xojo.com/armando_sorbi/32/934_2.png) [@Armando\_SORBI](https://forum.xojo.com/u/Armando_SORBI)\
**Post date:** [January 7, 2016, 6:32pm UTC](https://forum.xojo.com/t/moving-data-between-arrays/29069/3 "2016-01-07T18:32:43Z")

</div>

Nothing doing. I tried what you suggested but I still get “An exception of class OutOfBoundsException was not handled. The application must shut down.”

---

<div class="post-metadata">

**Author:** ![DaveS](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/848f3c/32.png) [@DaveS](https://forum.xojo.com/u/DaveS)\
**Post date:** [January 7, 2016, 6:41pm UTC](https://forum.xojo.com/t/moving-data-between-arrays/29069/4 "2016-01-07T18:41:00Z")

</div>

```auto
Dim Arr() as string
Dim Nnn(), i as integer
s=TextField1.text

Arr=s.Split(",")

For i=0 to arr.ubound
Nnn.append=val(Arr(i))
Next
```

and while you may not intended it. “Nothing doing” usually is interpeted as an arrogant response…

---

<div class="post-metadata">

**Author:** ![Eli\_Ott](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/5f8ce5/32.png) [@Eli\_Ott](https://forum.xojo.com/u/Eli_Ott)\
**Post date:** [January 7, 2016, 7:31pm UTC](https://forum.xojo.com/t/moving-data-between-arrays/29069/5 "2016-01-07T19:31:47Z")

</div>

> [@239840:@Dave S](#):
>
> “Nothing doing” usually is interpeted as an arrogant response…

He probably meant “not working”.

---

<div class="post-metadata">

**Author:** ![Armando\_SORBI](https://forum.xojo.com/user_avatar/forum.xojo.com/armando_sorbi/32/934_2.png) [@Armando\_SORBI](https://forum.xojo.com/u/Armando_SORBI)\
**Post date:** [January 8, 2016, 9:35am UTC](https://forum.xojo.com/t/moving-data-between-arrays/29069/6 "2016-01-08T09:35:07Z")

</div>

Sorry about the “nothing doing”. Of course I did not mean to be arrogant or to insult anybody, I just meant, as Eli Ott said, it did not work. As good as you can speak or write a language which is not your own, there are always some “nuances” that might cheat you.  
Thanks everybody for your help. Again, accept my apologies.

---

<div class="post-metadata">

**Author:** ![Grant\_Singleton](https://forum.xojo.com/letter_avatar_proxy/v4/letter/g/b38774/32.png) [@Grant\_Singleton](https://forum.xojo.com/u/Grant_Singleton)\
**Post date:** [January 8, 2016, 12:27pm UTC](https://forum.xojo.com/t/moving-data-between-arrays/29069/7 "2016-01-08T12:27:08Z")

</div>

Alternatively, you could use the iterator loop function and avoid declaring an unneeded integer variable:

[code]Dim Arr() as string  
Dim Nnn() as integer  
s=TextField1.text

Arr=s.Split(",")

For each sArr as string in Arr  
Nnn.Append val(sArr)  
Next[/code]

---

<div class="post-metadata">

**Author:** ![Armando\_SORBI](https://forum.xojo.com/user_avatar/forum.xojo.com/armando_sorbi/32/934_2.png) [@Armando\_SORBI](https://forum.xojo.com/u/Armando_SORBI)\
**Post date:** [January 8, 2016, 7:08pm UTC](https://forum.xojo.com/t/moving-data-between-arrays/29069/8 "2016-01-08T19:08:13Z")

</div>

Ok, it seems to work.  
There is one thing I cannot figure out:  
If I fill an array with a string and convert that string into integers stored in a second array, the latter should treat what’s inside as numbers.

dim s as string  
dim a, b, i as integer

Dim Arr() as string  
Dim Nnn() as integer  
s=TextField1.text

Arr=s.Split(",")

For each sArr as string in Arr  
Nnn.Append val(sArr)  
if Nnn(i)\<0 then //I’m counting the negative numbers into variable a  
a=a+1  
else  
b=a //The first time it encounters a positive number b should be made equal to a  
end if  
Next

If I fill Arr() with this sequence: “-2,-3,4,4,4,4,4,-6,-6,-6,-6,-7” I get the same sequence in Nnn() but the if will not recognize the third number as a positive and keeps on increasing a.

---

<div class="post-metadata">

**Author:** ![Eli\_Ott](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/5f8ce5/32.png) [@Eli\_Ott](https://forum.xojo.com/u/Eli_Ott)\
**Post date:** [January 8, 2016, 7:11pm UTC](https://forum.xojo.com/t/moving-data-between-arrays/29069/9 "2016-01-08T19:11:00Z")

</div>

In the following line you are using a variable i which is always 0:

```auto
if Nnn(i)<0 then
```

---

<div class="post-metadata">

**Author:** ![Eli\_Ott](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/5f8ce5/32.png) [@Eli\_Ott](https://forum.xojo.com/u/Eli_Ott)\
**Post date:** [January 8, 2016, 7:13pm UTC](https://forum.xojo.com/t/moving-data-between-arrays/29069/10 "2016-01-08T19:13:48Z")

</div>

[code] Dim s As String = “-2,-3,4,4,4,4,4,-6,-6,-6,-6,-7”  
Dim arr() As String = s.Split(",")  
Dim nnn() As Integer  
Dim a As Integer  
Dim b As Integer

For i As Integer = 0 To arr.Ubound  
Dim value As Integer = Val(arr(i))  
nnn.Append(value)  
If value \< 0 Then  
a = a + 1  
Else  
b = a  
End  
Next[/code]

---

<div class="post-metadata">

**Author:** ![Armando\_SORBI](https://forum.xojo.com/user_avatar/forum.xojo.com/armando_sorbi/32/934_2.png) [@Armando\_SORBI](https://forum.xojo.com/u/Armando_SORBI)\
**Post date:** [January 8, 2016, 7:15pm UTC](https://forum.xojo.com/t/moving-data-between-arrays/29069/11 "2016-01-08T19:15:55Z")

</div>

I guess I’m still a little bit green, am I?  
Thank you

---

<div class="post-metadata">

**Author:** ![Eli\_Ott](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/5f8ce5/32.png) [@Eli\_Ott](https://forum.xojo.com/u/Eli_Ott)\
**Post date:** [January 8, 2016, 7:31pm UTC](https://forum.xojo.com/t/moving-data-between-arrays/29069/12 "2016-01-08T19:31:23Z")

</div>

When something is not working out with calculations and loops and so, I usually take it apart like that:

` Dim ub As Integer = arr.Ubound
  For i As Integer = 0 To ub
    Dim entry As String = arr(i)
    Dim value As Integer = Val(entry)
    nnn.Append(value)
    Dim isNegative As Boolean = ( value < 0 )
    If isNegative Then
      a = a + 1
    Else
      b = a
    End
  Next`  
You see that there is no line anymore with two statements or assignments in it. In the debugger I then can step over it line by line and I’ll find the error faster. If you have a line like this:

```auto
Nnn.Append val(sArr)
```

… you mix two things. Of course this is a silly example, because the result of Val(sArr) will be visible immediately in the debugger at the end of the nnn array. But you get the idea.

---

<div class="post-metadata">

**Author:** ![Grant\_Singleton](https://forum.xojo.com/letter_avatar_proxy/v4/letter/g/b38774/32.png) [@Grant\_Singleton](https://forum.xojo.com/u/Grant_Singleton)\
**Post date:** [January 8, 2016, 11:59pm UTC](https://forum.xojo.com/t/moving-data-between-arrays/29069/13 "2016-01-08T23:59:44Z")

</div>

@Armando SORBI, the example I posted works if you have to do some work on every element of an array without having to know the index of the element that’s being worked on through each iteration of the loop. If you need to test each element on it’s way through from a string to an integer, then you’ll have to do it like @Eli Ott has shown you.

By the way, why are you using an array of strings as numbers and then converting them to integers? Are they coming from a database?

You could use:

```auto
dim Nnn() as integer = array(-2,-3,4,4,4,4,4,-6,-6,-6,-6,-7)
```

Don’t worry about being a little green, we’ve all been there, and this forum has many many helpful and smart members to assist.

I’m a little green myself, in regards to C++ programming. I’ve started looking into creating Xojo plugins that extend the functionality of Xojo with some useful routines instead of using Win32 API declares.

Cheers

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [January 9, 2016, 1:01am UTC](https://forum.xojo.com/t/moving-data-between-arrays/29069/14 "2016-01-09T01:01:48Z")

</div>

The alternative would be not to bother with a numeric array, and simply use the string array as it is, converting to integer as the array is accessed.

---

<div class="post-metadata">

**Author:** ![Armando\_SORBI](https://forum.xojo.com/user_avatar/forum.xojo.com/armando_sorbi/32/934_2.png) [@Armando\_SORBI](https://forum.xojo.com/u/Armando_SORBI)\
**Post date:** [January 9, 2016, 1:10pm UTC](https://forum.xojo.com/t/moving-data-between-arrays/29069/15 "2016-01-09T13:10:25Z")

</div>

Thank you everybody

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 6:08pm UTC](https://forum.xojo.com/t/moving-data-between-arrays/29069/16 "2020-10-29T18:08:07Z")

</div>


