Results 1 to 5 of 5

Thread: Array element assignment

  1. #1
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,782
    Rep Power
    10

    Array element assignment

    Next preview version will have the possibility to assign multiple values in one go to array elements.
    So the following syntax will be accepted:

    [code=thinbasic]
    ElementNumber = 1
    MyArray(ElementNumber) = FirstValue, SecondValue, ..., nthValue
    [/code]

    thinBasic will assign FirstValue to MyArray(ElementNumber), SecondValue to MyArray(ElementNumber + 1) and so on. Equivalent code is
    [code=thinbasic]
    MyArray(1) = FirstValue
    MyArray(2) = SecondValue
    ...
    MyArray(nth) = nthValue
    [/code]

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

    An example example using variant array:
    [code=thinbasic]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
    [/code]

    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
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  2. #2
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    67
    Posts
    3,869
    Rep Power
    404

    Re: Array element assignment

    Another very useful and nice feature that is for sure!! Thanks Eros.
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  3. #3
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,129
    Rep Power
    732

    Re: Array element assignment

    Yes,

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

    Bye,
    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  4. #4

    Re: Array element assignment

    Nice

  5. #5
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,782
    Rep Power
    10

    Re: Array element assignment

    This is now included in official release
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •