Moving data between Arrays

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

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))

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

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…

He probably meant “not working”.

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.

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]

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.

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

if Nnn(i)<0 then

[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]

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

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:

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.

@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:

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

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.

Thank you everybody