|
-
Jun 13th, 2000, 04:03 AM
#1
Thread Starter
New Member
I'm working on a project that let access people from many places in my country to a Database, this program may work with many conections at a time, at this moment i have a dynamic array of Winsocks, add is very simple... but when one of the connections is "closed by peer" I get the Close event, there i close the socket, i unload it, and when i try to reindex the other sockets i can't, i get a hole in my array, why?
can anyone help me?
on the MSDN CD says, try setting a new index, but when i try to assign an index to the object it generates an error, a friend told me "change the object name before unload it" but i don't know if change the name of an object can be possible, it is?
another idea?
thanx for any support.
JJDriVeR
-
Jun 13th, 2000, 04:44 AM
#2
Instead of trying to ReIndex the Control Array, why not just reuse those Indexes that are leaving holes in the Array? You could write a simple function to get the next available Index for you, i.e.
Code:
Function GetNextID(oObjArray As Variant) As Long
Dim nIndex As Long
Dim oObj As Variant
Dim bFound As Boolean
For nIndex = 0 To oObjArray.Count
bFound = False
For Each oObj In oObjArray
If oObj.Index = nIndex Then
bFound = True
Exit For
End If
Next
If Not bFound Then Exit For
Next
GetNextID = nIndex
End Function
Example:
Code:
Private Sub Command1_Click()
MsgBox "The next Index is " & GetNextID(wskArray)
End Sub
-
Jun 13th, 2000, 04:54 AM
#3
transcendental analytic
Or you could use a classcollection instead of object array and it will automatically remove the holes when you remove an item
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Jun 13th, 2000, 06:28 PM
#4
Thread Starter
New Member
Thanx in advance
Thanx for the help I'll use it, and thanx too for the other suggestion i will not use it because i need to redo many code that is implemented based on an array, but for the next time I will try in that new way...
thanx to both and for any other reply!
JJDriVeR
-
Aug 23rd, 2001, 01:09 PM
#5
Addicted Member
I have an array of thousands of items and if the hole(s) are
torwards the end of the array, it takes time to find the missing
arrayitems with that loop.
So, I created a seperate array of indexes that keeps track of
deleted items. (You could also create a comma delimited string as well).
VB Code:
Private mintControlCount As Integer
Private mintIndexCount as Integer
Private intIndexes() as Integer
Private Sub Remove(Index As Integer)
'You cant unload the original control (In my case it is objItems(0))
If Index <> 0 Then
'You dont need to add to the indexes if the removed control is
'the last control
If mintControlCount - 1 <> Index Then
'Add a new item to the index array
Redim Preserve intIndexes(mintIndexCount)
intIndexes(mintIndexCount) = Index
'Iterate the index counter
mintIndexCount = mintIndexCount + 1
End If
Unload objItems(Index)
'De-Iterate the control counter
mintControlCount = mintControlCount - 1
End If
End If
End Sub
When you create new controls, check for any items in the Index array first. If there are none then use the top control as the new
control.
Always looking for a better and faster way!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|