Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
suggestion: initialize array values within the DIM statement
#6
(12-21-2022, 05:23 AM)Pete Wrote: 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

Yup, both good approaches. I'm just trying to be lazy and not have to type all that extra code.  Big Grin
Reply


Messages In This Thread
RE: suggestion: initialize array values within the DIM statement - by bobalooie - 12-21-2022, 05:47 PM



Users browsing this thread: 1 Guest(s)