PDA

View Full Version : Array element assignment



ErosOlmi
01-06-2007, 11:24
Next preview version will have the possibility to assign multiple values in one go to array elements.
So the following syntax will be accepted:



ElementNumber = 1
MyArray(ElementNumber) = FirstValue, SecondValue, ..., nthValue


thinBasic will assign FirstValue to MyArray(ElementNumber), SecondValue to MyArray(ElementNumber + 1) and so on. Equivalent code is


MyArray(1) = FirstValue
MyArray(2) = SecondValue
...
MyArray(nth) = nthValue


This will be possible with any numeric, string or variant array.

An example example using variant array:

uses "console"

Dim ArrayNamesAndValues(4) As variant
Dim Counter as long

ArrayNamesAndValues(1) = 1, "ABC", 123, "Hello world"

for Counter = 1 to 4
console_writeline ArrayNamesAndValues(Counter)
next
console_waitkey


I'm still working on this new feature adding error checking (mainly bounds checking).
It will work also on multi dim array but only with one index following colum order. So for example if MyArray is a 4 x 3 matrix (4 lines, 3 colums) MyArray(5) will be in reality MyArray(2,1).

Hope you will like it.
Eros

kryton9
01-06-2007, 18:16
Another very useful and nice feature that is for sure!! Thanks Eros.

Petr Schreiber
01-06-2007, 19:20
Yes,

I like it too.
It is logical and it will help improve parsing performance.

Bye,
Petr

Michael Hartlef
02-06-2007, 09:57
Nice :)

ErosOlmi
19-06-2007, 10:21
This is now included in official release