how to omit repeated values in a FOR loop

Results 1 to 3 of 3

Thread: how to omit repeated values in a FOR loop

  1. #1
    JohnH Guest

    Default how to omit repeated values in a FOR loop

    in the [FOR] loop that i am trying to write, i need to be able to handle the possibility of repeated values appearing in an array value.<BR><BR>&#060;%<BR>ArrayVariable = "1,2,2,2,2,1,3"<BR><BR>parsedString = Split(ArrayVariable, ",")<BR><BR>for counter = 0 To UBound(parsedString)<BR><BR>response.write(ParsedS tring(counter)&"<BR>")<BR><BR>Next<BR>%&#062;<BR>T his will output each of the numeric values to the page, but i cannot figure out how to skip any repeated values. I have tried to nest another split statement with accompanying loop, carrying a comparison If-Else statement to avoid repeats - with a total lack of success. <BR>Is there a built-in component in vbscript that will help me? or perhaps a better way to approach this?<BR><BR>Thanks in Advance.<BR>Massively frustrated<BR>JH

  2. #2
    BalletChick Guest

    Default RE: how to omit repeated values in a FOR loop

    Well... you could sort the array before outputting it... then it would be farily easy to see if each value to were about to print matched the one you just printed... if it did, you could skip it. OR, you could do something kludgy but effective... like this:<BR><BR>&#060;%<BR>ArrayVariable = "1,2,2,2,2,1,3"<BR><BR>parsedString = Split(ArrayVariable, ",")<BR><BR>strKeepTrack = ""<BR>for counter = 0 To UBound(parsedString)<BR><BR>if instr(strKeepTrack, ParsedString(counter) & "&#124") = 0 then<BR>&nbsp;&nbsp;&nbsp;response.write(ParsedStr ing(counter)&"<BR>")<BR>&nbsp;&nbsp;&nbsp;strKeepT rack = strKeepTrack & ParsedString(counter) & "&#124"<BR>end if<BR><BR>Next<BR><BR>strKeepTrack = ""<BR><BR>%&#062;<BR><BR>:)<BR>

  3. #3
    JohnH Guest

    Default Thank you

    perfect!<BR> solved my problem , muchas gracias<BR>JH

Posting Permissions

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