Results 1 to 7 of 7

Thread: Putting an array inside of an array.

  1. #1

    Thread Starter
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    Putting an array inside of an array.

    Not sure if this is the appropriate forum, but it sounds like something a graphics programmer might have had to deal with before.

    Let's say I have a 2D array of boolean, representing the surface of a monochrome screen. Let's say I have another 2D Array, representing an object to place in that screen, and want to put it in a specific place inside the first array. i.e,

    00000000
    00000000
    00000000
    00000000
    00000000
    00000000

    is my first array

    and

    11
    11

    is my second.

    What would be a good way (in psuedocode) to do something like this

    InsertArray(4,3)

    That would result in the original array looking like

    00000000
    00000000
    00011000
    00011000
    00000000
    00000000

    Any suggestions? Obviously the arrays are much bigger, but the idea should be the same regardless..

    Bill
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

  2. #2

    Thread Starter
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    Re: Putting an array inside of an array.

    I found a way to do it if I know beforehand the size of the array being placed into the first array. Is there a way to get the dimensions of a 2D array? For example, if I have a 4x4 array, and call Array.Length, I will get 16. Since it won't always be a square, is there a way to find out how the 2D array is structured?

    Bill
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

  3. #3
    Fanatic Member Nove's Avatar
    Join Date
    Jul 2004
    Posts
    736

    Re: Putting an array inside of an array.

    In what language? If you're talking vb6, you would get the first two dimensions using ubound(array,1) and ubound(array,2).

  4. #4

    Thread Starter
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    Re: Putting an array inside of an array.

    Should have specified... This is C#, but There should be an equivalent to ubound there somewhere.. Thanks.

    Bill
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

  5. #5
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: Putting an array inside of an array.

    .NET uses Upperbound and LowerBound I think. Should be something like:
    VB Code:
    1. Array[].upperBound();
    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  6. #6
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Putting an array inside of an array.

    Code:
    myArray.GetUpperBound(0); // first dimension
    myArray.GetUpperBound(1); // second dimension

  7. #7
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: Putting an array inside of an array.

    So what are you doing?

    If you have the main array (mainA() and the new array newA()), and you have a function Insert( left,top,newA()), then you could:

    Loop through dimension 0
    Loop through dimension 1
    mainA(top plus outer loop, left plus inner loop) = newA(outer loop, inner loop)

    That is roughly what could be done. Of course, you would only need to loop through a range defined by top+size of newA() dimension 0, and left+ size of newA() dimension 1.
    My usual boring signature: Nothing

Posting Permissions

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



Click Here to Expand Forum to Full Width