Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
suggestion: initialize array values within the DIM statement
#9
I liked mn's example.

Well, I don't see a function, because we are returning a set of array values, not just a single value; so a sub seems a more likely choice...

Code: (Select All)
REDIM LNUMS(0): myray LNUMS(), "1, 2, 5, 8, 4000"

FOR i = 1 TO 5
    PRINT lNUMS(i)
NEXT

SUB myray (myarray(), myarray_elements AS STRING)
    DO
        i = i + 1
        j = INSTR(seed, myarray_elements + ",", ",")
        IF j = 0 THEN EXIT DO
        REDIM _PRESERVE myarray(i)
        myarray(i) = VAL(MID$(myarray_elements, seed + 1, j - seed - 1))
        seed = j + 1
    LOOP
END SUB

Now I think we need to restrict it to dynamic arrays, to avoid a duplicate definition. Maybe this could be expanded on to handle string arrays, too. As far as how to define them by type, single, long, etc. That's more complicated.

Edit: Steve was posting while I was writing. I se the same method.In fact, just recently in my replies to the password thread.

Pete
Reply


Messages In This Thread
RE: suggestion: initialize array values within the DIM statement - by Pete - 12-21-2022, 07:01 PM



Users browsing this thread: 2 Guest(s)