'by wankoilz
url=InputBox("Enter the full download address:")
threadCount=InputBox("Input number of threads (no more than 10, too many will be cumbersome):")
fileName=GetFileName(url)
filePath=GetFilePath()
Set ohttp=CreateObject("")
Set ado=CreateObject("")
Set fso=CreateObject("")
=1
=3
"Head",url,True
Do While <>4
200
Loop
'Get file size
fileSize=("Content-Length")
'Create a temporary file of the same size as the download file, for the following ado segment rewrite
(filePath&"TmpFile",True,False).Write(Space(fileSize))
(filePath&"TmpFile")
blockSize=Fix(fileSize/threadCount):remainderSize=fileSize-threadCount*blockSize
upbound=threadCount-1
'Define an array containing objects, and the number of members is the number of threads
'Direct Dim array name (variable name) is not possible, here I use Execute to modify it
Execute("Dim arrHttp("&upbound&")")
For i=0 To UBound(arrHttp)
startpos=i*blockSize
endpos=(i+1)*blockSize-1
If i=UBound(arrHttp) Then endpos=endpos+remainderSize
Set arrHttp(i)=CreateObject("")
arrHttp(i).open "Get",url,True
'Segment download
arrHttp(i).setRequestHeader "Range","bytes="&startpos&"-"&endpos
arrHttp(i).send
Next
Do
200
For i=0 To UBound(arrHttp)
If arrHttp(i).readystate=4 Then
'Whenever a thread finishes downloading, it will be written to the corresponding location of the temporary file
=i*blockSize
MsgBox "Thread"&i&"Downloaded!"
arrHttp(i).responseBody
arrHttp(i).abort
complete=complete+1
End If
Next
If complete=UBound(arrHttp)+1 Then Exit Do
timeout=timeout+1
If timeout=5*30 Then
'Set according to file size
MsgBox "30 seconds timeout!"
End If
Loop
If (filePath&fileName) Then (filePath&fileName)
(filePath&"TmpFile")
(filePath&fileName)
MsgBox "File downloaded!"
Function GetFileName(url)
arrTmp=Split(url,"/")
GetFileName=arrTmp(UBound(arrTmp))
End Function
Function GetFilePath(fullname)
arrTmp=Split(fullname,"\")
For i=0 To UBound(arrTmp)-1
GetFilePath=GetFilePath&arrTmp(i)&"\"
Next
End Function