Results 1 to 11 of 11

Thread: Arrays: Removing Items

  1. #1

    Thread Starter
    Addicted Member mouse88's Avatar
    Join Date
    Mar 2009
    Location
    South Wales, United Kingdom
    Posts
    225

    Arrays: Removing Items

    I'm wondering what the proper way to remove an item from an array is. The way i am doing it at the moment is:

    Code:
    MyArray(0) = Nothing
    Is this the best way to do it as i'm having problems with my programme and i think it may be something to do with this?

  2. #2
    Frenzied Member Campion's Avatar
    Join Date
    Jul 2007
    Location
    UT
    Posts
    1,098

    Re: Arrays: Removing Items

    The proper way is to move everything ABOVE the item down 1 slot, and then resize the array. It's relatively simple, but does take a little coding. In place of using an actual Array, I recommend you use a List(of T) instead.
    From my burrow, 2 feet under.

  3. #3

    Thread Starter
    Addicted Member mouse88's Avatar
    Join Date
    Mar 2009
    Location
    South Wales, United Kingdom
    Posts
    225

    Re: Arrays: Removing Items

    That wont work as I need everything else in the array to stay where it is

  4. #4

    Thread Starter
    Addicted Member mouse88's Avatar
    Join Date
    Mar 2009
    Location
    South Wales, United Kingdom
    Posts
    225

    Re: Arrays: Removing Items

    I also can't use the list as i'm using a two dimensional array

  5. #5
    Frenzied Member Campion's Avatar
    Join Date
    Jul 2007
    Location
    UT
    Posts
    1,098

    Re: Arrays: Removing Items

    What type are you putting into the array then? Why are you using a single dimension in code if it's multi-dimensional?
    From my burrow, 2 feet under.

  6. #6

    Thread Starter
    Addicted Member mouse88's Avatar
    Join Date
    Mar 2009
    Location
    South Wales, United Kingdom
    Posts
    225

    Re: Arrays: Removing Items

    The array contains graphics from a class that i have created. I was just using that code as an example what i'm actually doing is:

    Code:
    Blocks(TestPosition.X, TestPosition.Y) = Nothing

  7. #7
    Fanatic Member Vectris's Avatar
    Join Date
    Dec 2008
    Location
    USA
    Posts
    941

    Re: Arrays: Removing Items

    What your "problems with my program".
    If your problem is solved, click the Thread Tools button at the top and mark your topic as Resolved!

    If someone helped you out, click the button on their post and leave them a comment to let them know they did a good job

    __________________
    My Vb.Net CodeBank Submissions:
    Microsoft Calculator Clone
    Custom TextBox Restrictions
    Get the Text inbetween HTML Tags (or two words)

  8. #8

    Thread Starter
    Addicted Member mouse88's Avatar
    Join Date
    Mar 2009
    Location
    South Wales, United Kingdom
    Posts
    225

    Re: Arrays: Removing Items

    Basically I am setting certain items in the array to nothing and when rendering all blocks in the array to the screen its still displaying the items that have been set to nothing. I have put breakpoints on my code and I checked the array and the items are set to nothing so im not sure why it's still drawing the blocks.

  9. #9
    Fanatic Member Vectris's Avatar
    Join Date
    Dec 2008
    Location
    USA
    Posts
    941

    Re: Arrays: Removing Items

    Then maybe it's a problem with your code somewhere else
    If your problem is solved, click the Thread Tools button at the top and mark your topic as Resolved!

    If someone helped you out, click the button on their post and leave them a comment to let them know they did a good job

    __________________
    My Vb.Net CodeBank Submissions:
    Microsoft Calculator Clone
    Custom TextBox Restrictions
    Get the Text inbetween HTML Tags (or two words)

  10. #10

    Thread Starter
    Addicted Member mouse88's Avatar
    Join Date
    Mar 2009
    Location
    South Wales, United Kingdom
    Posts
    225

    Re: Arrays: Removing Items

    Ye that's what I was thinking but im starting to loose hope i've been through my code lots of times and still can't figure out why. If i'm removing blocks that were originally in the array then it works fine but if im removing a block that was added to the array then it sets it to nothing but still display it on screen.

  11. #11
    Fanatic Member Vectris's Avatar
    Join Date
    Dec 2008
    Location
    USA
    Posts
    941

    Re: Arrays: Removing Items

    maybe we could help you if we saw your code?
    If your problem is solved, click the Thread Tools button at the top and mark your topic as Resolved!

    If someone helped you out, click the button on their post and leave them a comment to let them know they did a good job

    __________________
    My Vb.Net CodeBank Submissions:
    Microsoft Calculator Clone
    Custom TextBox Restrictions
    Get the Text inbetween HTML Tags (or two words)

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