How do I add items to a listbox while the script is still being processed

125 pts.
VB 2010 express
visual basic 2010
I have a script that goes out and downloads files from a url. In my form I have a listbox that I use like a message queue. After each download I send a completion notice to the listbox. The problem I am having is the messages only get sent at the end of my script. In short, I download several hundred files and the completion messages are not received in my listbox till after all the files have completed downloading. Does anyone have any suggestions that I may follow, so that after each download it will send the message to the listbox before the next download starts?
 Dim GetMe As Integer
        Dim MeURL As String
        Dim MePath As String

        MeURL = "https://my url to download here"

        MePath = "c:my path to save download"

        GetMe = URLDownloadToFile(0, MeURL, MePath, 0, 0)

        listbox1.Items.Add("this file download completed")
'repeat the above code mutiple times

Software/Hardware used:
Visual Basic 2010 express

Answer Wiki

Thanks. We'll let you know when a new response is added.

Thank you my friend, that worked! I just added the refresh before each additional download and it worked great.

Discuss This Question: 6  Replies

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • carlosdl
    Is that the code you are actually using, or an example of how you would like to do it?

    Also, what kind of 'script' is it?  Do you have the script's code? what language is it written in?
    85,390 pointsBadges:
  • TryingHard

    It's written in VB with touches of C# converted for use into the VB script. The download portion of the code is the actual code I am using. I wanted to add something visual I code look at to let me know where I was in the download process, as I didn't want a progress bar. The script handles the download dialog box that is shown when navigating to the url. I then download the file to a folder on my PC. The URL is handled by a webbrowser control within my script (not shown above). I have several (x100) files I download and in between each download I would like the list box to say " such and such file completed" but what I am getting is the script will download all the files and only then will the listbox update with all the " such and such file completed" messages. It's not updating after each file download and I don't understand why not. I tried something like

    do until listbox1.Items.contain("this file download completed")

    listbox1.Items.Add("this file download completed")



    but this doesn't work... I'm not sure what approach I should try next and I'm not sure why the listbox is only updating after the script has completed.

    125 pointsBadges:
  • CarlCioffi
    It doesn't look like you are refreshing the listbox on the form for one and if this is a web interface then I would assume it won't refresh the listbox until you do a post back.  If you are in a loop in a windows form then it is probably acting the way it thinks it needs to and is only repainting the form after completion of the script.
    345 pointsBadges:
  • CarlCioffi

    In this code example the listbox refreshes after each iteration, without the refresh the listbox only refreshes at the end of the loop.


    345 pointsBadges:
  • CarlCioffi

    Well that didn't work let's try that again. It didn't past in my code so I will just enter it here.

        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            For I As Integer = 1 To 10
                ListBox1.Items.Add(I.ToString + " test number 1")
            Button1.Enabled = False
        End Sub
    Without the highlighted code the listbox only refreshes after the loop exits.
    345 pointsBadges:
  • CarlCioffi
    Glad to be of assistance.
    345 pointsBadges:

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.


Share this item with your network: