Closed dynamicboy closed 5 months ago
Hi @dynamicboy I've already answered this in your previous post. Array of SB and sVB behaves as value types not reference types, to make it easy for kids. So, each single operation on any array will create a new array, even when you change an item at any index! So, when you copy the inner array, every time tou change an item of it, you will get a totally different array, hence the original array is not changed. This is designed by the Small Basic compiler, so when you try this in MS Small Basic you will get the same result.
A[1][1] = 1
A[1][2] = 2
A[1][3] = 3
A[2][1] = 100
A[2][2] = 200
A[2][3] = 300
For i= 1 To 2
ItemArr= a[i]
ItemArr[2] = 0
endfor
To solve this, you should index the original array, or save the modified inner array back to it as yopu did in the last sample:
A = {{1, 2, 3}, {100, 200, 300}}
For I = 1 To 2
A[I][2] = 0
Next
TW.WriteLine(A.ToStr())
Thanks.
Understood, thank you! Additionally, the sVB reference book appears to be missing the File.WriteArray and File.ReadArray functions.
Thanks for the hint. I will add these two methods to the next update of the book.
From: dynamicboy @.> Sent: Tuesday, June 25, 2024 9:25 AM To: VBAndCs/sVB-Small-Visual-Basic @.> Cc: Mohammad Hamdy Ghanem @.>; Comment @.> Subject: Re: [VBAndCs/sVB-Small-Visual-Basic] Inner array elements of a multi-dimensional array seems immutable. I can't change it directly. (Issue #70)
Understood, thank you! Additionally, the sVB reference book appears to be missing the File.WriteArray and File.ReadArray functions.
— Reply to this email directly, view it on GitHubhttps://github.com/VBAndCs/sVB-Small-Visual-Basic/issues/70#issuecomment-2188413894, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ALQ5MVWVESL6DZJU3XYN5ULZJEZRLAVCNFSM6AAAAABJZ2PQY2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCOBYGQYTGOBZGQ. You are receiving this because you commented.Message ID: @.***>
version: sVB 3.0.7.4 details: Inner array elements of a multi-dimensional array seems immutable. I can't change it directly. code:
screenshot: