Login Register






[VB6] [Source] Download with ProgressBar and Stats with Inet filter_list
Author
Message
[VB6] [Source] Download with ProgressBar and Stats with Inet #1
Download with ProgressBar and Stats with Inet

[Image: rYjag.png]

Hello there, I made this a long time ago but modified a little today.
I also coded "Time remaining", but it was buggy and I can't debug properly because I don't have internet in my VM where I use VB6.

Thanks to:
[link=http://www.vbforums.com/showthread.php?t=311040]VB Forums[/link] for the basic code to download with ProgressBar

[link=http://www.multiupload.com/GEPY2BZ5NS]Download Exe[/link]

Spoiler: Source
Code:
Option Explicit Private Declare Sub InitCommonControls Lib "comctl32.dll" () Dim DownloadProgress As Integer, CurrentSize As Double, Seconds As Long Dim tempSize As Double, lngFileLength As Double Private Sub cmdDownload_Click() On Error GoTo ErrReturn If tURL.Text = "http://" Then Exit Sub CancelError = True DialogTitle = "Choose a location to Save" FileName = Right(tURL.Text, Len(tURL.Text) - InStrRev(tURL.Text, "/")) Dim ext As String ext = Right(tURL.Text, Len(tURL.Text) - InStrRev(tURL.Text, ".")) Filter = "." & ext & "|." & ext & "|All Files|*.*" InitDir = Environ("USERPROFILE") & "\Desktop" ShowSave ProgressBar1.Visible = True ProgressBar1.Value = 0 Timer1.Enabled = True DownloadFile tURL.Text, FileName Timer1.Enabled = False If Seconds <= 60 Then lRem.Caption = "Download Complete" & vbCrLf & "Time Elpased: " & Seconds & " seconds" ElseIf Seconds <= 360 And Seconds >= 61 Then Dim Minutes As Byte Minutes = Seconds / 60 lRem.Caption = "Download Complete" & vbCrLf & "Time Elapsed: " & Minutes & " minutes" & Seconds & " seconds" End If lbl.Caption = "Click here to open File location" & vbCrLf & "Total Size: " & Round(CurrentSize / 1024, 2) & "Mb" ProgressBar1.Visible = False Exit Sub ErrReturn: End Sub Private Sub Form_Initialize() InitCommonControls End Sub Private Sub Form_Load() pic.BackColor = RGB(220, 220, 220) ProgressBar1.Visible = False End Sub Public Sub DownloadFile(strURL As String, strDestination As String) Const CHUNK_SIZE As Long = 1024 Dim intFile As Integer, lngBytesReceived As Double Dim strHeader As String, b() As Byte, i As Integer DoEvents With Inet1 .URL = strURL .Execute , "GET", , "Range: bytes=" & CStr(lngBytesReceived) & "-" & vbCrLf While .StillExecuting DoEvents Wend strHeader = .GetHeader End With strHeader = Inet1.GetHeader("Content-Length") lngFileLength = Val(strHeader) DoEvents If lngFileLength = 0 Then Exit Sub lngBytesReceived = 0 intFile = FreeFile() Open strDestination For Binary Access Write As #intFile Do b = Inet1.GetChunk(CHUNK_SIZE, icByteArray) Put #intFile, , b lngBytesReceived = lngBytesReceived + UBound(b, 1) + 1 DownloadProgress = Round((lngBytesReceived / lngFileLength) * 100, 1) ProgressBar1.Value = Round(DownloadProgress) CurrentSize = Round((lngBytesReceived / 1024), 2) lbl.Caption = CurrentSize & " kB of " & Round((lngFileLength / 1024), 2) & " kB Downloaded" DoEvents Loop While UBound(b, 1) > 0 Close #intFile End Sub Private Sub lbl_Click() Shell "explorer.exe " & Left(FileName, InStrRev(FileName, "\")), vbNormalFocus End Sub Private Sub Timer1_Timer() On Error GoTo er lRem.Caption = DownloadProgress & "% Done" & vbCrLf & "Download Speed: " & CurrentSize - tempSize & " Kb/s" Seconds = Seconds + 1 tempSize = CurrentSize er: End Sub Private Sub Form_Unload(Cancel As Integer) Unload Me End End Sub
[Image: rytwG00.png]
Redcat Revolution!

Reply

RE: [VB6] [Source] Download with ProgressBar and Stats with Inet #2
May i ask you something? why your progress bar is so special? O.~
[Image: 5DQAS.gif]

May the force be with you...

Reply

RE: [VB6] [Source] Download with ProgressBar and Stats with Inet #3
(01-25-2011, 12:18 PM)Lenalee Wrote: May i ask you something? why your progress bar is so special? O.~

Glad somebody asked. This is my own creation. Smile

Read this for more info.
[VB6] [Source] vProgress - A ProgressBar like WPF's
[Image: rytwG00.png]
Redcat Revolution!

Reply

RE: [VB6] [Source] Download with ProgressBar and Stats with Inet #4
awsome! its the same you posted before hc went :rip:

love your work even if its in vb2 :lp:

@Lenalee the special thing is that a normal download will be:
my.computer.network.downloadfile(textbox1.text, "C:\server.exe")

but coder's download has a status which counts how many kb/s and the progressbar is accurate. not like a timer that adds 1 value to the progressbar every sec :|
Pierce the life fibers with your drill.

Reply

RE: [VB6] [Source] Download with ProgressBar and Stats with Inet #5
(01-25-2011, 12:31 PM)1234hotmaster Wrote: awsome! its the same you posted before hc went :rip:

love your work even if its in vb2 :lp:

[..]

Added a tray icon this time. Link updated. Smile
[Image: rytwG00.png]
Redcat Revolution!

Reply

RE: [VB6] [Source] Download with ProgressBar and Stats with Inet #6
(01-25-2011, 12:28 PM)Coder-san Wrote:
(01-25-2011, 12:18 PM)Lenalee Wrote: May i ask you something? why your progress bar is so special? O.~

Glad somebody asked. This is my own creation. Smile

Read this for more info.
[VB6] [Source] vProgress - A ProgressBar like WPF's

ROFL, nice creation u have here Tongue Thx for the share^^
[Image: 5DQAS.gif]

May the force be with you...

Reply