HTTPSOCKET - Download Multiple Files with Progress bar


I am trying to add a progress bar to my file download app but am running into some issues. My application allows the user to select multiple files from a listbox and import them all in one go. The process was working fine before I added the progress bar to the mix. Now everytime I try to download more than 1 file, only one file completes the download process and the others can be found in the destination folder but with zero byte size. Any help would be greatly appreciated.

here is my code


[code] ImportPB.Enabled = false
ProgressBar1.Value = 0

For i As Integer = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) Then
dim filename as string = listbox1.cell(i,0)
dim source as string = filename
Dim f as FolderItem = SpecialFolder.Pictures.child(filename)
TCPSocket.Get(source, f)
End If

For the TCPSocket


Label2.Visible = true ProgressBar1.Visible = true


For i As Integer = 0 To ListBox1.ListCount - 1 If ListBox1.Selected(i) Then if totalBytes = 0 then ProgressBar1.Maximum = 0 else ProgressBar1.Maximum =100 ProgressBar1.Value = (bytesReceived/totalBytes)*100 end end if next


[code] Label2.Visible = false
ProgressBar1.Visible = false

ImportPB.Enabled = true
ProgressBar1.Maximum = 100
ProgressBar1.Value = 0[/code]

I am far from an export on file transfers, but I’m going to try to help.
Since you have placed the TCPSocket.Get(source, f) inside a tight for…next loop, the code will not wait for your first item to DL before calling the next item. I would think you might have more success if you triggered the next item in your list from the DownloadComplete event. Put your items in a queue. When you get a DLcomplete from the first, trigger the second and so on.

Thanks for your response Roger. How do I go about triggering each consecutive download in the downloadcomplete event? Would it be a loop in the download complete event? if so, wouldn’t that bring me back to the same issue?

Something like this…
Create an array and append the files to be downloaded to it.

Dim DLarray(-1) As string
For i As Integer = 0 To ListBox1.ListCount - 1
   If ListBox1.Selected(i) Then
       DLarray.append listbox1.cell(i,0)
   end if

Now you have a list of files to be downloaded. the list is DLarray.Ubound + 1 long
Keep a ct Integer of where you are.
In a method…

Dim f as FolderItem = SpecialFolder.Pictures.child(DLarray(ct)) TCPSocket.Get(source, f)
When you get the DownloadComplete event then…

if ct < ubound(DLarray) Then ct = ct + 1 //repeat the download for the next in line else //we're done end if

You’ll have to flush that code out, but it should give you a start.

Ok so i tried what you provided but i get a DLarray does not exist under the DownloadComplete event. Sorry I am new to xojo so i may be declaring it wrong. How do I declare a new item like array etc. so that it is accessible by all subs.

You’ll need to declare it at the scope which is appropriate for your design, probably at the window or class level . Perhaps read up on scope in the Xojo docs

Thanks Roger