clearing/deleting data in array

omoba

Active Member
Licensed User
Longtime User
Hi,

Pls how do I set my array back to blank (Zero --nothing in array).

I created some random numbers put them in the array and used them.

Now I am done with them and need to generate another set of random numbers.

How do I set the array to initial empty state?

Thanks
 

Mahares

Expert
Licensed User
Longtime User
You can just redim the variable like this:
B4X:
Dim MyVar(4) As String
For i=0 To 3
   MyVar(i)=i
Next
Msgbox(MyVar(0) & "  " & MyVar(1) & "  " & MyVar(2) & "  " & MyVar(3),"") 
Dim MyVar(2)
For i=0 To 1
   MyVar(i)=i +5
Next
Msgbox(MyVar(0) & "  " & MyVar(1),"")
 
Upvote 0

omoba

Active Member
Licensed User
Longtime User
Thanks,

I was doing that. My problem was somewhere else. I wasnt entering the correct integers in the array.

I was doing

For i = lower to upper
numbers(i) = numbers(i) + 1
Next i


instead of
For i = 0 to 10
numbers(i) = lower + i
Next i

where lower and upper are my ranges


Both look the same to me but I am getting different result. Maybe someone can explain this to me
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Sure. In the first case you add 1 to each element of the array. In the second, you set each element to your lower value plus element's index. These are different things, except if numbers(i)=i and lower=1.
 
Upvote 0
Top