Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Range of values
Message
 
 
À
05/11/2001 15:47:27
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivie
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Divers
Thread ID:
00577572
Message ID:
00577588
Vues:
17
>>>Does anybody have a function that converts a range of values into individual values? The best example, I think, is the range of pages in newer versions of MS-Word, where the user can type "1, 3-5, 7". I want this converted to a form that can easily be processed, like the string "1, 3, 4, 5, 7", or an array or cursor with the corresponding elements.
>>>
>>>I am sure I can write the function myself, but it seems to me this is a rather involved procedure.
>>>
>>>Hilmar.
>>
>>It doesn't seem complicated to me. I just wrote it in my head. Hint: use for loop :)
>
>OK, I'll try it. Actually, when I wrote "difficult", I was thinking mainly about the string parsing. It isn't difficult in terms of commands required, but all the detail work, and checking invalid user input.
>
>Hilmar.

See my other reply. If the only delimiter is comma, then in VFP7 you use can alines, in VFP6 you should convert comma into chr(13) first. Or you can use FoxTools to get array of words, e.g.:
*!******************************************************************************
FUNCTION aparser
     *  Description.......: Function parses a text string into an array.  
     *                    : Each element of the array contains one word...
     *  Calling Samples...: dimension laWords[1]
     *                    : lcWordString = "Some text string"
     *                    : lnWords = aparser(@laWords, lcWordString)
     *  Parameter List....: paWords, pcWordString, pcDelimiter
     ********************************************************************
     lparameter paWords, pcWordString, pcDelimiter
     local lnWords, lni
     external array paWords

     if not "FOXTOOLS.FLL" $ set("library")
          set library to foxtools.fll additive
     endif

     pcDelimiter = iif(empty(pcDelimiter), space(1), pcDelimiter)

     lnWords = Words(pcWordString, pcDelimiter)

    IF lnWords>0 && Not empty string 
          dimension paWords[lnWords]

          for lni = 1 to lnWords
               paWords[lni] = WordNum(pcWordString, lni, pcDelimiter) && Array of words
          endfor
     ELSE
         dimension paWords[1] && For empty string lnWords=0
         paWords[1]=""
     ENDIF         
     return lnWords
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform