DAY 007: _PRESERVE
#2
Woohoo! Another one that needs no <bag> tag from me.

Steve's second example is how I set up my W.P. database read/write file system. I need speed for that, as it can handle thousands of text line entries. Sam-Clip I'm starting with the first example for the beta phase. Why? Because it's simple to implement and track. With the first method I can just use ubounds() as the terminal entry.

Now here's one I love that wasn't mentioned, array shuffling...

Let's say you have 10 arrays and you want to cut of numbers 3 through 6.
Code: (Select All)
REDIM c$(10)
FOR i = 1 TO 10: c$(i) = CHR$(64 + i): PRINT c$(i);: NEXT 'ABCDEFGHIJ"
PRINT
x1 = 3: x2 = 6 ' Cut this range out.
FOR i = 1 TO 10
    IF i >= x1 AND i <= x2 THEN
        c$(i) = "nul" ' Tag and bag.
    END IF
NEXT
i = 0: j = 0: terminate = UBOUND(c$)
DO
    i = i + 1
    IF c$(i + j) = "nul" THEN
        DO
            j = j + 1
        LOOP UNTIL c$(i + j) <> "nul" OR i + j = terminate
    END IF
    c$(i) = c$(i + j)
LOOP UNTIL i + j = terminate
REDIM _PRESERVE c$(i): terminate = UBOUND(c$)
FOR i = 1 TO terminate
    PRINT c$(i);
NEXT

You can add to an array in a similar manner. Other methods exist, feel free to post what you use REDIM _PRESERVE for!

Pete
Reply


Messages In This Thread
DAY 007: _PRESERVE - by SMcNeill - 11-12-2022, 08:35 AM
RE: DAY 007: _PRESERVE - by Pete - 11-12-2022, 10:31 AM
RE: DAY 007: _PRESERVE - by mnrvovrfc - 11-12-2022, 03:13 PM
RE: DAY 007: _PRESERVE - by SMcNeill - 11-12-2022, 03:58 PM
RE: DAY 007: _PRESERVE - by Pete - 11-12-2022, 04:02 PM



Users browsing this thread: 3 Guest(s)