Click here to Skip to main content
16,020,840 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to correct this code? I use winsock and listview. I want all subitems added every ConnectionRequest changes as timer ticks. When I run this code the Timer only runs in the last subitem.

Option Explicit

Dim wIndex, wPort As Integer
Dim sec As Integer
Dim LM As ListItems

Private Sub Form_Load()
    sec = 0
    wIndex = 1
    wPort = 1
End Sub

Private Sub Winsock1_ConnectionRequest(Index As Integer, ByVal requestID As Long)
    wIndex = wIndex + 1
    wPort = wPort + 1
    Load Winsock1(wIndex)
    With Winsock1(wIndex)
            .Close
            .LocalPort = wPort
            .Accept requestID
    End With
    Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
    Set LM = ListView1.ListItems(Index)
            LM.SubItems(2) = sec + 1
End Sub
Posted
Updated 25-May-11 0:27am
v2
Comments
ZeeroC00l 25-May-11 6:28am    
-- edited for pre tag

1 solution

Set LM = ListView1.ListItems(Index)

What is Index in the context of the timer method? Could it be you need wIndex instead? Also, place Option Explicit at the beginning of the module to avoid errors like this one.

Good luck!




You are using Index but it isn't defined anywhere (I can't see it in your example). So you would need to setup multiple timers, for example in the form load:
For i=1 to 10
  Load Timer1(i)
  Timer1(i).interval = 100
  Timer1(i).enabled = true
Next i


The event handler would need the Index as parameter. Something like this:
Private Sub Timer1(Index As Integer)
 ' Timer code
End Sub
 
Share this answer
 
v2
Comments
derodevil 26-May-11 0:09am    
wIdex is for Winsock. No problem with the Winsock. I have problem with the timer. I also tried to index the winsock but it doesn't work either. Help me please
E.F. Nijboer 26-May-11 4:09am    
You are using Index but it isn't defined anywhere. I added some code to the original solution that should work. Maybe you could give that a try.
derodevil 26-May-11 15:09pm    
It doesn't work as expected. Would you mind if I send you the source code. You can correct it anyway. I'll repost here the solution for other members. I'm sorry my English is bad, I'm Indonesian. Thanks for helping me.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900