Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2002
    Location
    Columbus Ohio
    Posts
    1

    Post Unanswered: looking for a Visual Fox Pro class or function

    Hi There ,

    I am looking for a function (or a class) similar to scatter.
    However, instead of pasting a whole record into an array,
    I would like to paste an expression into an array. This expression is
    a field in a table and it has different values delimited by commas (in the same
    field).

    I wonder if there is a function class in this frame work which would allow me
    to scatter each value of this field into a seprate array cell.

    For instance, I have this expression:
    "box,cs,bx"

    Each value is delimited by commas. So I want to copy each value to an array;
    let's say A[i] where i=1,2,3

    So
    A[1] = "box"
    A[2]="cs"
    A[3]="bx"

    This example is containing 3 values with length between 2 and 3 characters. But we could have an expression with 4, 5 6, ...X values and lengths between 1 to 4 characters. The ideal function should be able to work for any of these scenarios.

    How could this be acomplished?
    Thanks for your help!

  2. #2
    Join Date
    Jul 2002
    Location
    Rotterdam NY
    Posts
    2
    IF NOT EMPTY(ESCATTER(',','~',fieldname))
    IF ALEN(expArray)>0
    MESSAGEBOX('DO SOMETHING HERE WITH THIS ARRAY')
    ENDIF
    ENDIF
    RELEASE expArray


    FUNCTION ESCATTER
    LPARAMETER lcDelimiter,lcTerminator,lcString

    LOCAL i,lnCommas
    LOCAL lcExpression

    lcString = ALLTRIM(lcString)

    IF EMPTY(lcString)

    expArray = ''

    ELSE

    IF RIGHT(lcString,1) = lcDelimiter && the delimiter
    lcString = lcString + lcTerminator && the tilde is the string terminator
    ELSE
    lcString = lcString + lcDelimiter + lcTerminator
    ENDIF
    lnCommas = OCCURS(lcDelimiter,lcString)

    RELEASE expArray
    PUBLIC ARRAY expArray(lnCommas)

    FOR i = 1 TO lnCommas
    lcExpression = SUBSTR(lcString,1,AT(lcDelimiter,lcString)-1)
    lcString = SUBSTR(lcString,AT(lcDelimiter,lcString)+1)
    expArray(i) = lcExpression
    ENDFOR

    ENDIF

    RETURN expArray



    The code can be shortened this is just an example.

    Best regards
    Dan
    Last edited by danielborden; 10-08-02 at 08:31.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •