Announcement

Collapse
No announcement yet.

Wish List

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Michael Mattias
    replied
    When I saw the function header, all I saw was 'a' and 'b' but I was looking for something like "start" and "end" or "first" and "last."

    You fooled me. Fooled me good.

    Leave a comment:


  • John Gleason
    replied
    Originally posted by Michael Mattias View Post
    >that's a totally different function from some kind of 'enhanced JOIN$'
    Steve Bouffe wanted to do this:
    Code:
    A$ = JOIN$( Array(10 to 20), $CRLF)
    and the code I posted does this:
    Code:
    a = joPar(Array(), 10, 20, $CRLF)
    That is a correct way I believe to do it. I like the MACRO idea too.
    ____________________________________________


    Originally posted by Michael Mattias View Post
    Single Function to process any array type...
    .. and use the ARRAYATTR function to query the size of the elements.
    MCM
    Thanks for the tip! Never used it like that before.

    Leave a comment:


  • Rodney Hicks
    replied
    Perhaps this is the reason that it is left the way it is. Each of us having a slightly different concept of how to go about it. I would have used a macro.
    I'm not sure that any of us would be more 'right' in how we go about it.

    Rod
    PS
    Poll could have used "Don't know" and/or "Don't care" as additional option(s).
    Last edited by Rodney Hicks; 18 Jul 2008, 09:02 AM. Reason: add postscript

    Leave a comment:


  • Michael Mattias
    replied
    Just for the record, you do not have to change the code to deal with fixed string arrays of varying element size.

    You can use the technique demonstrated here... Single Function to process any array type (CC3/Win7+) 12-17-03

    .. and use the ARRAYATTR function to query the size of the elements.

    MCM

    Leave a comment:


  • Michael Mattias
    replied
    >And in the meantime until that happy day...



    Unless I have totally lost it, that's a totally different function from some kind of 'enhanced JOIN$'

    Leave a comment:


  • John Gleason
    replied
    And in the meantime until that happy day...
    Code:
    #COMPILE EXE
    #DIM ALL
    
    'FUNCTION joPar() joins dynamic string arrays or parts of them
    FUNCTION joPar(arr() AS STRING, a AS LONG, b AS LONG, delim AS STRING) AS STRING
       LOCAL x, y, lod AS LONG
       LOCAL jStr AS STRING
    
       x = STRPTR(arr(a))
       y = STRPTR(arr(b))
       IF (x AND y) = 0 THEN ? "Error, invalid array type or array element": EXIT FUNCTION
    
       lod = LEN(delim)
       jStr = SPACE$(y - x + LEN(arr(b)) + (b - a + 1) * lod) 'make big enough string to hold join
       x = 1
    
       FOR y = a TO b
          MID$(jStr, x) = arr(y)       'write an arr element
          x = x + LEN(arr(y))
          MID$(jStr, x) = delim        'join it
          x = x + lod
       NEXT
       FUNCTION = LEFT$(jStr, x - (lod + 1)) 'trim excess
    END FUNCTION
    
    'FUNCTION joParF() joins fixed string arrays or parts of them. String len needs to be specified each time used.
    'In this example it is STRING * 100
    FUNCTION joParF(arr() AS STRING * 100, a AS LONG, b AS LONG, delim AS STRING) AS STRING
       LOCAL x, y, lod AS LONG
       LOCAL jStr AS STRING
    
       x = VARPTR(arr(a))
       y = VARPTR(arr(b))
       IF (x AND y) = 0 THEN ? "Error, invalid array type or array element": EXIT FUNCTION
    
       lod = LEN(delim)
       jStr = SPACE$(y - x + LEN(arr(b)) + (b - a + 1) * lod)
       x = 1
    
       FOR y = a TO b
          MID$(jStr, x) = arr(y)
          x = x + LEN(arr(y))     '<< can replace w/ x = x + 100 (whatever fixed str len is) for efficiency
          MID$(jStr, x) = delim
          x = x + lod
       NEXT
       FUNCTION = LEFT$(jStr, x - (lod + 1))
    END FUNCTION
                 
                  'join parts of arrays using functions joPar & joParF
    FUNCTION PBMAIN () AS LONG
        LOCAL a AS STRING, ii AS LONG, ip AS LONG PTR, t AS SINGLE
        DIM strArr(5000) AS STRING
        DIM strArr2(5000) AS STRING * 100
        OPEN "c:\joPar1dTest.txt" FOR OUTPUT AS #1
        
        FOR ii = 0 TO 5000
           strArr(ii) = REPEAT$(ii, "ooo")
           strArr2(ii) = STR$(ii) & "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
        NEXT
        t = TIMER
                                                       
         PRINT #1, joPar (strArr(),  751, 1250, $CRLF)
         PRINT #1, joParF(strArr2(), 1954, 2004, $CRLF)
         
       ? "k" & STR$(TIMER - t)
    END FUNCTION

    Leave a comment:


  • Michael Mattias
    replied
    Well, you should send in the NSF; it sounds pretty usable.

    But this is the kind of situation where I just write my own function make sure it's includeable so I can re-use it. (Or if I'm in a good mood, post a demo here).

    What comes to mind here is a header ...
    Code:
    FUNCTION JoinPartOfArray (s() AS STRING, delim AS STRING, _
              OPTIONAL startsub as LONG, OPTIONAL endsub AS LONG) AS STRING 
    
     code here
    
    END FUNCTION
    If endSub not passed use UBOUND.; if startsub not passed use LBOUND.

    CALLS:
    Code:
      S$ = JoinPartOfArray (foo(),"*", 5)  ' from subscript 5 to end using * 
      S$ = JoinPartOfArray (foo(), ",", 6, 32) ' from subs 5 to 32 only using comma
     S$ = JoinPartOfArray (foo(), "|")       ' whole array (= JOIN$) using pipe
    Write once, use many

    MCM
    Last edited by Michael Mattias; 16 Jul 2008, 04:25 PM.

    Leave a comment:


  • Eros Olmi
    replied
    Anyhow, I think PB support would prefer an official request made at support at powerbasic dot com.
    So better to send them a mail in any case regardless what will be the results of this poll.

    Leave a comment:


  • Eros Olmi
    replied
    For me yes,

    but only if both indexes are optional:
    Code:
    JOIN$( Array([IdxStart [TO IdxEnd]]) [, delim])
    Regards
    Eros

    Leave a comment:


  • Steve Bouffe
    started a poll Wish List

    Wish List

    12
    Yes
    58.33%
    7
    No
    41.67%
    5
    Create string of an array.

    A$ = JOIN$( Array(), $CRLF)

    Would be great is we could specify parameters to join a section of the array.

    A$ = JOIN$( Array(10 to 20), $CRLF)
Working...
X