Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
QB64_GJ_LIB ARRay Library
#2
You may be wondering why did I make this? I am sick of writing the same code over and over again, and thought a higher level library would keep me from going crazy.

All of these things are built into a lot of other languages I use; python, php, javascript.

So...

Instead of:

Code: (Select All)

    DIM AS LONG ub, lb, i, n
    lb& = LBOUND(source_arr$) : ub& = UBOUND(source_arr$)
    IF start_idx% < lb& OR start_idx% + count% > ub& THEN EXIT SUB ' out of range
    IF ub& - lb& < count% THEN EXIT SUB ' too many and not enough
    REDIM dest_arr(0 TO ABS(count%)) AS STRING
    IF SGN(count%) = -1 THEN
        IF ((start_idx% - 1) - ABS(count%)) < 0 THEN EXIT SUB ' out of range
        n& = 0
        FOR i& = (start_idx% - 1) TO ((start_idx% - 1) - ABS(count%)) STEP -1
            dest_arr$(n&) = source_arr$(i&)
            n& = n& + 1
        NEXT i&
    ELSE
        IF ((start_idx% + 1) + ABS(count%)) > (ub& - lb&) THEN EXIT SUB ' out of range
        n& = 0
        FOR i& = start_idx% + 1 TO ((start_idx% + 1) + count%) STEP 1
            dest_arr$(n&) = source_arr$(i&)
            n& = n& + 1
        NEXT i&
    END IF

I can:
Code: (Select All)

CALL ARR_STR.slice(s1$(), s2$(), 1, 3)

etc.
grymmjack (gj!)
GitHubYouTube | Soundcloud | 16colo.rs
Reply


Messages In This Thread
QB64_GJ_LIB ARRay Library - by grymmjack - 08-21-2023, 12:07 AM
RE: QB64_GJ_LIB ARRay Library - by grymmjack - 08-21-2023, 12:12 AM
RE: QB64_GJ_LIB ARRay Library - by a740g - 08-21-2023, 08:56 AM
RE: QB64_GJ_LIB ARRay Library - by mnrvovrfc - 08-21-2023, 12:50 PM



Users browsing this thread: 2 Guest(s)