03-05-13, 10:43 PM
السلام عليكم
- أدرج أداة ونسوك وضع قيمة الخاصية Index تساوي صفر . ثم إستخدم هذا الكود :
- أدرج أداة ونسوك وضع قيمة الخاصية Index تساوي صفر . ثم إستخدم هذا الكود :
كود :
Private Function Is_PortInUse(zPort As Long) As Boolean
On Error GoTo zER
Is_PortInUse = True
Winsock1(0).Close
DoEvents
Winsock1(0).LocalPort = zPort
DoEvents
Winsock1(0).Listen
DoEvents
Winsock1(0).Close
DoEvents
Is_PortInUse = False
Exit Function
zER:
If Err.Number <> 0 Then
Is_PortInUse = True
Exit Function
Else
Err.Clear
End If
End Function
Private Sub Form_Load()
If List1.ListCount > 0 Then
Dim I As Integer
Dim R As Integer
For I = 0 To List1.ListCount - 1
If Trim$(List1.List(I)) <> "" And IsNumeric(Trim$(List1.List(I))) = True Then
If Is_PortInUse(Val(Trim$(List1.List(I)))) = False Then
R = R + 1
DoEvents
Load Winsock1(R)
DoEvents
Winsock1(R).LocalPort = Val(Trim$(List1.List(I)))
DoEvents
Winsock1(R).Listen
DoEvents
End If
End If
Next
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
If Winsock1.Count > 1 Then
Dim I As Integer
Dim zCount As Integer
zCount = Winsock1.Count - 1
For I = 1 To zCount
Unload Winsock1(I)
DoEvents
Next
End If
End Sub
