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

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,879 10-29-2025, 05:44 AM
Last Post: bplus
  Array out of passing arrays... Pete 2 407 09-22-2025, 08:53 PM
Last Post: ahenry3068
  Huge array of variable length strings mdijkens 9 1,830 10-17-2024, 02:01 PM
Last Post: mdijkens
  An Array v's A Dictionary Dimster 10 1,868 10-08-2024, 06:59 PM
Last Post: TempodiBasic

Forum Jump:


Users browsing this thread: