non repeating array - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

non repeating array

[b][red]This message was edited by Rico124a at 2004-9-4 18:43:44[/red][/b][hr]
How would you go about creating an array that would not repeat results?
example:
I want 15 different results from
aTrait: array [1..100] of string =

thanks


Comments

  • zibadianzibadian Posts: 6,349Member
    : [b][red]This message was edited by Rico124a at 2004-9-4 18:43:44[/red][/b][hr]
    : How would you go about creating an array that would not repeat results?
    : example:
    : I want 15 different results from
    : aTrait: array [1..100] of string =
    :
    : thanks
    :
    :
    What do you mean by 15 different results? If you want 15 different arrays with 100 string elements, you can either create 15 different array variables, or a 2-D array with in the second dimension 15 elements.
  • Rico124aRico124a Posts: 6Member
    : : [b][red]This message was edited by Rico124a at 2004-9-4 18:43:44[/red][/b][hr]
    : : How would you go about creating an array that would not repeat results?
    : : example:
    : : I want 15 different results from
    : : aTrait: array [1..100] of string =
    : :
    : : thanks
    : :
    : :
    : What do you mean by 15 different results? If you want 15 different arrays with 100 string elements, you can either create 15 different array variables, or a 2-D array with in the second dimension 15 elements.
    :
    Your giving me way too much credit. Just a simple 1-D array of 100 string elements all pertaining to colors (from white to black). I input that I want 15 colors from that array. What I want to see is 15 different colors spit out into a memobox.
    example: white, red, blue, black, green, yellow, pink, etc .
    not: red, red, blue, green, pink, red, puse, etc.
    Thanks
  • zibadianzibadian Posts: 6,349Member
    : : : [b][red]This message was edited by Rico124a at 2004-9-4 18:43:44[/red][/b][hr]
    : : : How would you go about creating an array that would not repeat results?
    : : : example:
    : : : I want 15 different results from
    : : : aTrait: array [1..100] of string =
    : : :
    : : : thanks
    : : :
    : : :
    : : What do you mean by 15 different results? If you want 15 different arrays with 100 string elements, you can either create 15 different array variables, or a 2-D array with in the second dimension 15 elements.
    : :
    : Your giving me way too much credit. Just a simple 1-D array of 100 string elements all pertaining to colors (from white to black). I input that I want 15 colors from that array. What I want to see is 15 different colors spit out into a memobox.
    : example: white, red, blue, black, green, yellow, pink, etc .
    : not: red, red, blue, green, pink, red, puse, etc.
    : Thanks
    :
    The trick here is to fill a 15-element array in such a way they you check each element to be added with all previous elements. Here is a simple example:
    [code]
    var
    ColorToBeAdded: string;
    ColorsArray: array[1..15] of string;
    NumColor: integer;
    i: integer;
    FoundColor: boolean;
    begin
    // Example Initializion: Run only once
    NumColor := 0;
    ColorToBeAdded := 'red';
    // Start of "real example code"
    FoundColor := False; // Assume the color isn't in the list
    if NumColor > 0 then // Check if there are already some added
    for i := 1 to NumColor do
    if ColorToBeAdded = ColorsArray[i] then
    FoundColor := true; // Found a matching color
    if not FoundColor then // Add the new color
    begin
    inc(NumColor);
    ColorsArray[NumColor] := ColorToBeAdded;
    end;
    end;
    [/code]
    This code will add the color red to the array. If you run the "real example code" twice with red as color, you will find only 1 element is filled, and NumColor is still 1. Only if you add a non-red color, it will be added.
Sign In or Register to comment.