#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    2
    Rep Power
    0

    Unhappy deleting array contents


    hi, i need to finish my program by sunday night, and its now sat afternoon, but i need serious help! i have an array to store records, but one of the options i wanted to include was to delete one of the records in the array. The prblem is that i dont know how! is there some kind of function, or do i have to type out some code? the only way i couls see past it was to overwrite the next record into the array onto the one that i want to delete. the problem with that is that then i have two records in a row that are identical.

    Please help if you can, i'm getting really desperate! either post a reply or email me on imperial_overlord@hotmail.com. Thanks!

    mike.
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,638
    Rep Power
    4247
    Normally we don't do homework on the forum, but since you've actually shown some effort, I'll give you a hand. Let's say the array is 12 elements long and you want to delete the element at position 5. What you want to do is copy element 6 to element 5, element 7 into element 6, element 8 into element 7 and so on, all the way to the end of the array. To do this, the trick is to use a for, repeat or while loop to do it. I'll give you some pseudo code (assuming index = 5 and arraysize = 12)
    Code:
    { Shift all the elements by 1 }
    for i := index to arraysize - 1 do
        array[i] := array[i+1];
    
    array[arraysize] := 0; { Blank out the last element }

    Comments on this post

    • lo_p_ez agrees : Thanks!! I'm starting with Ruby and I was looking forward to solve this problem ;)
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    2
    Rep Power
    0

    thanks!


    hey!

    thanks for trying, but i've handed my project in already! And we were allowed to do ask for help from other people so long as we said so in the project! At least now i know for future reference!

    mike

IMN logo majestic logo threadwatch logo seochat tools logo