Help with arrays
BlitzPlus Forums/BlitzPlus Programming/Help with arrays
| ||
Hi, I know types by heart (I think) but the concept of how arrays work is lost on me. So basically, an array looks something like this: Dim DataX(3) ;where 3 equals the number of data to be stored For x = 0 To 3 DataX(x) = x Next ;this FOR - NEXT loop seems to cycle through the array until the number of integers (3) reaches 3, then it goes "next" I honestly don't see how this can store data. The tutorial says you can even store strings in an array, but this is all really complicated. I'm much better-suited to types it seems, but I'd sure love to know more about arrays. |
| ||
Normally, you could have a single variable called for instance DataX:DataX = 1 With arrays, you can enumerate this variable: Dim DataX(3) DataX(0) = 1 DataX(1) = 999 DataX(2) = 34 DataX(3) = 123 You could do this instead: DataX0 = 1 DataX1 = 999 DataX2 = 34 DataX3 = 123 It would do the same, however, with a 'Dim' array, you can use another variable as the index: p = 1 DataX(p) = 999 With a For..Next loop, the program loops a variable between a start and an end value For p = 0 to 3 print p Next So, combine those two methods and you can fill an array with numbers: Dim DataX(3) For p = 0 to 3 DataX(p) = 999 Next for p = 0 to 3 Print "DataX("+p+") = " + DataX(p) next Types are a more advanced method of storing/looping through data. However 'Dim' arrays are a standard feature of Basic languages and in some situations, they could come in handy. |
| ||
sorry for my english but the expression correct is: dim dataX(3) for p = 0 to 2 ; not 3 dataX(p) = p next |
| ||
No, you can use dataX(3) also. The index range goes from zero to -in this case- three. |