|
-
Dec 7th, 2001, 06:31 PM
#1
Lively Member
Relax already, sheesh, we all can't sit here and read this board 24 - 7.
But since you asked so nicely, I am gonna show ya what you need. I have done multiple downloads through IRC, and this code works great for me. There are probably a couple of variables dimensioned that you do not need, so don't worry about them. The way I have it set up is I have a MDIChild form set up with a Winsock on it, and I just make a new instance of it everytime I want to download a new file. Set up a MDIChild form named whatever, mine's named DCCFileRecieved.
VB Code:
Public fileName As String
Public senderName As String
Public fileSize As String
Public I As Integer 'hold the file number of the opened file
Public totalSize As Double
Public goodFile As Boolean
Public lastTime As Long
Public Sub startNewSession(ip As String, port As String)
If WS.State <> sckClosed Then
WS.Close
End If
WS.Connect ip, port
T.Enabled = True
End Sub
Private Sub WS_DataArrival(ByVal bytesTotal As Long)
On Error GoTo err:
Dim strData As String
Dim size
WS.GetData strData, vbString
Print #I, strData;
size = LOF(I)
totalSize = totalSize + bytesTotal
lblRecieved.Caption = FormatNumber((totalSize / 1024), 2) & " K"
PB.Value = totalSize
If totalSize >= lblSize.Caption Then
Close #I
goodFile = True
WS.SendData lblSize.Caption
WS.Close
fileRecieveDone fileName, lblUserName.Caption
Unload Me
End If
err:
If err.Number <> 0 Then
If WS.State = 6 Then
Exit Sub
ElseIf err.Number = 11 Then
Resume Next
Else
Resume Next
End If
End If
End Sub
Public Sub openFile()
I = FreeFile
If Len(App.Path & "\Download\" & fileName) > 0 Then 'looks to see if file exists
Open App.Path & "\Download\" & fileName For Output As I
Close #I
End If
Open App.Path & "\Download\" & fileName For Output As I
End Sub
Private Sub T_Timer()
On Error Resume Next
DoEvents
Dim total As Double
total = (totalSize - lastTime)
lblSpeed.Caption = FormatNumber((total / 1024), 1) & " Kps"
lblTime.Caption = ((lblSize.Caption - totalSize) / total) * 60
lastTime = totalSize 'lastTime is the variable holding the size of the file the last
'time the timer was called
End Sub
Private Sub WS_Close()
If goodFile Then
Me.Caption = "File Recieved Successfully"
Else
Me.Caption = "Incomplete File"
End If
End Sub
On another form:
To download a file, use yourFormNameHere.startNewSession(ip, port)
In case of a water landing, my head may be used as a flotation device.
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
|