O omoba Active Member Licensed User Longtime User Jan 20, 2013 #1 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
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
M Mahares Expert Licensed User Longtime User Jan 20, 2013 #2 You can just redim the variable like this: Code: Copy 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
You can just redim the variable like this: Code: Copy 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),"")
O omoba Active Member Licensed User Longtime User Jan 20, 2013 #3 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
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
mc73 Well-Known Member Licensed User Longtime User Jan 20, 2013 #4 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
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.
Erel B4X founder Staff member Licensed User Longtime User Jan 20, 2013 #5 In most cases it is easier to work with Lists. Upvote 0