 
| 
 
  Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum  was too unstable. Couple days, all good. If you notice any issues, please contact me. | 
Forum Index : Microcontroller and PC projects : MMBasic: Setting Array Elements
| Author | Message | ||||
| vegipete  Guru  Joined: 29/01/2013 Location: CanadaPosts: 1144 | 
 The statement DIM arry(2)=(16,17,21)is valid. Is there any reason why arry()=(17,17,11)couldn't also be valid, or is that just too perverse? Visit Vegipete's *Mite Library for cool programs. | ||||
| matherp Guru  Joined: 11/12/2012 Location: United KingdomPosts: 10539 | 
 Not perverse but not implemented and won't be | ||||
| JohnS Guru  Joined: 18/11/2011 Location: United KingdomPosts: 4106 | 
 Think what extra work would be required to recognise (parse) that :( As it starts out, it looks like a function call to arry. If it's not seen the name arry before it adds it to the internal data structures as a function. Then it finds the "=" and ... yuck. John | ||||
| jirsoft  Guru  Joined: 18/09/2020 Location: Czech RepublicPosts: 533 | 
 I know, it's not exactly the same, but I have already used: OPTION BASE 0 OPTION DEFAULT NONE OPTION EXPLICIT DIM INTEGER arry(2) = (16,17,21) printA(arry()) setA(arry(), "17,17,11") printA(arry()) END SUB printA(q() AS INTEGER) LOCAL INTEGER i, b = BOUND(q()) FOR i = 0 TO b ?q(i), NEXT i ? END SUB SUB setA(q() AS INTEGER, nq AS STRING) LOCAL STRING nv LOCAL INTEGER i FOR i = 0 TO BOUND(q()) nv = FIELD$(nq, i+1, ",") IF nv <> "" THEN q(i) = VAL(nv) ELSE ERROR "Not enough values" ENDIF NEXT i END SUB Jiri Napoleon Commander and SimplEd for CMM2 (GitHub), CMM2.fun | ||||
| vegipete  Guru  Joined: 29/01/2013 Location: CanadaPosts: 1144 | 
 That's OK. The following works as a straight forward enough substitute: a = 16 : b = 17 : c = 18The only nuisance is that you can't erase a variable that hasn't previously been dimmed into existence. dim arry(2)=(a,b,c) <some time later...> erase arry() : dim arry(2)=(c,b,a) In my case, I need to re-initialize starting values in the array, so I can use constant values, instead of variables: dim arry(2)=(1,2,3) . Edited 2021-03-07 04:07 by vegipete Visit Vegipete's *Mite Library for cool programs. | ||||
|  Print this page | 
|  | The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025  |