Results 1 to 3 of 3

Thread: Trouble With Arrays

  1. #1
    Join Date
    Sep 2007
    Location
    Behind You
    Posts
    72
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Trouble With Arrays

    Hello, this is JNCR and I am in a bit of a tricky situation. I have created the below as a rough representation of what I need. Don't even ask why my functions and variables are called what they are. I just made this up on the spot .

    In the procedure JNCR I want all of the Hi's available to have fun1 as Happy, and fun2 as Sad.

    Example:
    Since the array length is 5 (HowManyToDo const), I want the following:
    Hi[0].Happy := Fun1;
    Hi[0].Sad := Fun2;
    Hi[1].Happy := Fun1;
    Hi[1].Sad := Fun2;
    Hi[2].Happy := Fun1;
    Hi[2].Sad := Fun2;
    Hi[3].Happy := Fun1;
    Hi[3].Sad := Fun2;
    Hi[4].Happy := Fun1;
    Hi[4].Sad := Fun2;

    The tricky thing is that this needs to be dynamic. If the user types 188 as
    HowManyToDo then I want all of the Hi's Happy's and Sad's to be Fun1 and Fun2.

    SCAR Code:
    program NeedHelpWithArrays;

    Type
      Joe = Record
        Happy : String;
        Sad : String;
    end;

    Var
      i, RandomCase : Integer;
      Hi: array of Joe;
     
    Const
      HowManyToDo = 5;

    Function Fun1: String;
    begin
      RandomCase := Random(5);
      Case RandomCase of
        0: Result := 'age'
        1: Result := 'air'
        2: Result := 'anger'
        3: Result := 'animal'
        4: Result := 'answer'
        5: Result := 'apple'
      end;
    end;

    Function Fun2: String;
    begin
      RandomCase := Random(5);
      Case RandomCase of
        0: Result := 'car'
        1: Result := 'plane'
        2: Result := 'foot'
        3: Result := 'cheese'
        4: Result := 'querty'
        5: Result := 'cow'
      end;
    end;

    Procedure JNCR;
    begin
      SetArrayLength(Hi,HowManyToDo);
    {
      In here I want all of the Hi's available to have fun1 as Happy, and fun2 as Sad.
     
      Example:
        Since the array length is 5 (HowManyToDo const), I want the following:
        Hi[0].Happy := Fun1;
        Hi[0].Sad := Fun2;
        Hi[1].Happy := Fun1;
        Hi[1].Sad := Fun2;
        Hi[2].Happy := Fun1;
        Hi[2].Sad := Fun2;
        Hi[3].Happy := Fun1;
        Hi[3].Sad := Fun2;
        Hi[4].Happy := Fun1;
        Hi[4].Sad := Fun2;

        The tricky thing is that this needs to be dynamic.  If the user types 188 as
        HowManyToDo then I want all of the Hi's Happy's and Sad's to be Fun1 and Fun2.
    }

    end;

    begin
      JNCR;
    end.

    Any help would greatly be appreciated.

    ~JNCR
    The[Cheese] really puts it perfectly:

    Reflection is win

  2. #2
    Join Date
    Mar 2007
    Posts
    3,042
    Mentioned
    1 Post(s)
    Quoted
    14 Post(s)

    Default

    Something like the following maybe?:

    SCAR Code:
    for i := 0 to HowManyToDo - 1 do
    begin
      Hi[i].Happy := Fun1;
      Hi[i].Sad := Fun2;
    end;
    :-)

  3. #3
    Join Date
    Sep 2007
    Location
    Behind You
    Posts
    72
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Now there is something I missed... Thanks.

    ~JNCR
    The[Cheese] really puts it perfectly:

    Reflection is win

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Arrays, stuck on arrays
    By Camaro' in forum OSR Help
    Replies: 1
    Last Post: 03-08-2008, 02:02 AM
  2. Help with Arrays
    By kooldude in forum OSR Help
    Replies: 16
    Last Post: 06-15-2007, 05:36 AM

Posting Permissions

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