Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
suggestion: initialize array values within the DIM statement
#2
I suppose there are a couple of ways it could be coded into a function...

Code: (Select All)
DIM AS LONG LNUMS(5)
RESTORE mytmp
DIM a AS LONG
FOR i = 1 TO UBOUND(LNUMS)
    READ a
    LNUMS(i) = a
NEXT

mytmp:
DATA 1,2,5,8,4000

' Proof.
FOR i = 1 TO UBOUND(LNUMS)
    PRINT LNUMS(i)
NEXT

'--------------------- Next method...
ERASE LNUMS
'--------------------- Begin...

a$ = "{1, 2, 5, 8, 4000}"
a$ = MID$(a$, 2, LEN(a$) - 2)

FOR i = 1 TO UBOUND(LNUMS)
    j = INSTR(seed, a$ + ",", ",")
    LNUMS(i) = VAL(MID$(a$, seed + 1, j - seed - 1))
    seed = j + 1
NEXT

' Proof
FOR i = 1 TO UBOUND(LNUMS)
    PRINT LNUMS(i)
NEXT

I suppose it all depends on finding a dev who could use it frequently enough to include it in a future release.

Pete
Shoot first and shoot people who ask questions, later.
Reply


Messages In This Thread
RE: suggestion: initialize array values within the DIM statement - by Pete - 12-21-2022, 05:23 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Preserving multi-dim arrays Pete 5 416 12-19-2025, 03:17 PM
Last Post: Dimster
  Arbitrary CONST values Unseen Machine 31 2,936 10-29-2025, 05:44 AM
Last Post: bplus
  Array out of passing arrays... Pete 2 408 09-22-2025, 08:53 PM
Last Post: ahenry3068
  Huge array of variable length strings mdijkens 9 1,854 10-17-2024, 02:01 PM
Last Post: mdijkens
  An Array v's A Dictionary Dimster 10 1,887 10-08-2024, 06:59 PM
Last Post: TempodiBasic

Forum Jump:


Users browsing this thread: 1 Guest(s)