Array in an array - Printable Version +- QB64 Phoenix Edition (https://staging.qb64phoenix.com) +-- Forum: QB64 Rising (https://staging.qb64phoenix.com/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://staging.qb64phoenix.com/forumdisplay.php?fid=3) +---- Forum: Help Me! (https://staging.qb64phoenix.com/forumdisplay.php?fid=10) +---- Thread: Array in an array (/showthread.php?tid=1476) |
RE: Array in an array - TempodiBasic - 02-21-2023 (02-21-2023, 01:18 AM)Kernelpanic Wrote:Quote:@KernelPanic Hi kernelpanic Not you I was referring to my attempt to post an answer to you. First my two attempt are gone into void RE: Array in an array - mnrvovrfc - 02-21-2023 (02-21-2023, 02:26 PM)TempodiBasic Wrote: DIM myArray (1 to 4) AS INTEGER ' this is static Very good catch! However variable M cannot be zero if there should be a "1 TO" or any value at all higher than one. That doesn't seem to be indicated by the QB64 Wiki (I don't sleep well lately so my eyes are tired now): https://qb64phoenix.com/qb64wiki/index.php/DIM That older site linked to earlier only shows examples that worked in GW-BASIC, it must have been around to convert those old programs to run in QBasic... EDIT: Agree with you that this line should have been flagged by the IDE as an error: Code: (Select All) DIM AS Test xyz(1 TO 10, abc()) However I think that was presented as fake code by the OP. RE: Array in an array - Kernelpanic - 02-21-2023 Two examples for a dynamic and a static two-dimensional field. A static field is reinitialized with 0 after erase and can then be filled with new values again. However, it cannot be redimensioned like a dynamic field. So, 10 * 10 cannot become an 8 * 8 field. Dynamic array with Redim: Code: (Select All) 'Zweidimensionales Feld mit Redim neu dimensionieren - 29. Dez. 2022 Static array with Erase: Code: (Select All) 'Statisches Array. Keine Redimensionierung moeglich - 21. Feb. 2023 RE: Array in an array - Kernelpanic - 02-21-2023 (02-21-2023, 02:16 PM)bplus Wrote: @mnrvovrfc Erase can also be used for dynamic arrays, but it is redundant there as Redim includes Dim & Erase. RE: Array in an array - bplus - 02-21-2023 (02-21-2023, 06:04 PM)Kernelpanic Wrote:(02-21-2023, 02:16 PM)bplus Wrote: @mnrvovrfc No! RE: Array in an array - bplus - 02-21-2023 (02-21-2023, 02:26 PM)TempodiBasic Wrote:(02-21-2023, 01:07 AM)bplus Wrote: Nope! It is not about using variables for lbound or ubound.Hi dear This is a QB64 forum not QBasic here is Wiki for QB64: RE: Array in an array - bplus - 02-21-2023 @TempodiBasic and @Kernelpanic You can't do this either: Code: (Select All) Dim a(1 To 20) ' a is static When I first started doing QB64 this difference between Static arrays from DIM and Dynamic arrays from REDIM had me quite frustrated until I found ERASE was needed to clear a Static array. Please don't you guys mess up other people new to QB64 RE: Array in an array - Kernelpanic - 02-21-2023 Quote:No! But! You have misconceptions. Dynamic Arrays: After running Erase on dynamic arrays, the array is no longer known. It does not exist anymore. That's exactly what your screenshot shows. Redim includes both! Erase is first applied, then resized with Dim. QBasic, Page 188 Static: Add a Print to the first FOR loop and you'll see the values. After Erase, the array is reinitialized -> 0. Completely correct. RE: Array in an array - bplus - 02-21-2023 (02-21-2023, 06:45 PM)Kernelpanic Wrote:Quote:No! You can't run erase on a Dynamic array! I erased the Static array and showed it still existed but all the values cleared. Erase doesn't delete the array! Update: well I guess Erase does delete a dynamic array because that's what it says in Wiki for ERASE. Seems like an extra step if you want to clear all values. RE: Array in an array - Kernelpanic - 02-21-2023 To wrap it up, I meant it like this: Code: (Select All) Dim a(1 To 20) Erase only makes sense with dynamic arrays if one really want to delete the array - for whatever reason. QBasic is QuickBasic without the ability to create exe files. I have both the QuickBasic 4.5 manuals and the QBasic technical reference book. No difference in the matter! |