![]() |
Adjusting an array - Printable Version +- Mirage Source (https://mirage-engine.uk/forums) +-- Forum: Mirage Source (Nostalgia) (https://mirage-engine.uk/forums/forumdisplay.php?fid=61) +--- Forum: Archive (2006-2011) (https://mirage-engine.uk/forums/forumdisplay.php?fid=18) +---- Forum: Programming (https://mirage-engine.uk/forums/forumdisplay.php?fid=24) +----- Forum: Visual Basic 6 (https://mirage-engine.uk/forums/forumdisplay.php?fid=32) +----- Thread: Adjusting an array (/showthread.php?tid=2773) |
Adjusting an array - GIAKEN - 29-04-2009 Here's some code to adjust an array. This could mean boundless / dynamic arrays... The problem with them is for example: Player(1 To 1) When a player logs in it fills the first data, then a second comes in and you do ReDim Player(1 To UBound(Player) + 1) and you just have to loop through the UBound of the Player array...however, here is where adjusting an array comes in. Say for example player 2 leaves, you just do ReDim Preserve Player(1 To UBound(Player) - 1)...well what if Player 1 leaves? If you just get rid of the last part of the array it will leave the player 1 data and clear the player 2...so you have to switch the array around. Here's a form giving an example of rearranging an array I made: http://mayhem.auburnflame.com/frmArrayTest.frm Re: Adjusting an array - Jacob - 29-04-2009 You should learn to use "CopyMemory" api and copy the parts of the array. Later tonight I'll write up a bit of code to show how it's done. Re: Adjusting an array - GIAKEN - 29-04-2009 Yeah I'm sure there's better ways...I never use CopyMemory / ZeroMemory because I haven't really studied up on them yet. Re: Adjusting an array - Jacob - 30-04-2009 Here's a real quick class that will use a byte array. You can insert, insert at certain indexes and remove at certain indexes. I kinda tested it, if you see any problems let me know. Code: ' ************** This is a quick example of how to use it. Code: Dim t As New clsArray This is the output: Quote:Amount of items in array: 4 Re: Adjusting an array - Robin - 29-05-2009 The memory API is so fucking easy to use, and so much faster, I don't see why anyone wouldn't learn it. I'll check your code out later tonight, see if it's better than the one I use myself. |