Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pain in the Rear dynamic arrays

Status
Not open for further replies.

Rebis

Programmer
Aug 16, 2004
6
0
0
US
Howdy,

I am having fun playing with dynamic arrays. They used to be so cool in php.

I've been writing this app in vb 6, and it seems dynamic arrays are much harder to deal with.

I've managed to make an expand on demand array. thats good and fine. but now i need the array to be able to shrink on demand too. I need to be able to remove a record from anywhere in the array, and then shrink the array to fill the gap.

and then I'l need to remove a loaded control, in particular a winsock control.

any help anyone can offer will be much apprieciated.

many thanks,

/rebis
 
You will need to move all the entries beyond the deleted area down, then resize the array.

"I think we're all Bozos on this bus!" - Firesign Theatre [jester]
 
Or, if you're dealing with an array of objects, consider using a collection instead...

mmilan
 

Hi Jerry:

Another way to attack this problem is to copy the last item into the position of the item to be removed, then "ReDim Preserve" the array to remove the last item.

Like mmilan, if using arrays of objects, I use a collection, not an array.

Cassandra
 
Rebis, your subject header may be seen as a bit inappropriate and may lead to your thread being removed from the forum, so try to watch the language in your post.

Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 
Thats for the info there.

something like:
<code>

for i = numToDelete to uBound(arrayToDeleteFrom)
arrayToDeleteFrom(i) = arrayToDeleteFrom(i - 1)
next i

</code>

to remove the record from the array?

geez, not thought about that until now. that will probably work really well.

Moving on to cellections, i'm not sure what you mean here.
I have a dynamically on demand expanding control array.

Basically I have the app load in a new winsock control when a new connection request is received. After the fact all events which need to be sent to the client who connected on that port are dealt with using the connection number. for example, the first connection becomes known as 0 through the program. when 0 sends the disconect command (aptly named '/discon') i need to move all the remaining clients up one (so 1 becomes 0) so on and so forth.

I had through about adjusting the disconnected clients with a blocker value (if string = "disconed" then next i ) obviously this is not ideal as i would then have lots of unused winsock controls eating up space.

apologies if anyone found the original subject offensive, but i thought it as pretty apt, as, the hors i've been putting in are tiring on my butt, making them a real pain in the rear.

any help/advice anyone can offer will b e greatly appreiciated.

many thanks
 
Collections are kind of like hash arrays in PHP, though only suitable for objects. The key has to be a string as well (I think)

You can do away with the concept of a key for collections though (and I usually do unless there's a sensible application) and just treat them like normal arrays...

Something else to watch out for is the indexing of collections. Usually, any collection VB itself creates (columns on a grid say) will be 0 indexed (C anyone?), where as your own collections will be 1 indexed.

mmilan.
 
thanks for the headsup mmilan.

Does anyone have a FAQ or Tutorial link where I can fid out something more about collections?
I wasn't planning to move into complex database until the final write of the application, although it seems as thought it maybe nessecary to do so now.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top