Jump to content

I am very much struggling on a certain part in programming my VB project. So I am trying to get my VB Project to download a file and make a copy of it so it can be extracted properly. The only issue is that it keeps trying to extract the file while its downloading. Can I make it so it won't execute any more code until the download finishes? Thanks!

 


 

  Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5
   WC.DownloadFileAsync(New Uri("http://blahblah.com/test.zip"), "Resources\Downloading\test.zip")
            lblprogress.Text = "Downloading Zip File"
            
    REM HERE IS WHERE I WANT IT TO STOP UNTIL THE DOWNLOAD COMPLETES

My.Computer.FileSystem.CopyFile("Resources\Downloading\test.zip", "Resources\Downloaded\test.zip")
    
    REM WAIT UNTIL FILE IS DONE COPYING
   
        ZipFile.ExtractToDirectory("Resources\Downloaded\test.zip", "Extracted\test.zip")
    
    REM WAIT UNTIL UNZIPPING IS COMPLETE 
    
    lblprogress.text =  "Complete"
    
    REM The part below is for progress bar to show the download status
    Private Sub WC_DownloadProgressChanged(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs) Handles WC.DownloadProgressChanged
        DownloadProgress.Value = e.ProgressPercentage

 

Edited by CmzPlusHardware

Tech enthusiast and CS Student

 

 

 

 

 

Link to comment
https://linustechtips.com/topic/855319-visual-basic-help/
Share on other sites

Link to post
Share on other sites

8 minutes ago, CmzPlusHardware said:

I am very much struggling on a certain part in programming my VB project. So I am trying to get my VB Project to download a file and make a copy of it so it can be extracted properly. The only issue is that it keeps trying to extract the file while its downloading. Can I make it so it won't execute any more code until the download finishes? Thanks!

 


Thanks 

Can you put that segment of the code into a code quote.

Link to comment
https://linustechtips.com/topic/855319-visual-basic-help/#findComment-10651981
Share on other sites

Link to post
Share on other sites

1 minute ago, tjcater said:

Have you tried await?

I've heard of Await, but I am struggling on how to use it. I've seen it in other examples, but don't quite know how to use it in my case. 

 

(Note: My VB Skills is a somewhat moderate) 

Tech enthusiast and CS Student

 

 

 

 

 

Link to comment
https://linustechtips.com/topic/855319-visual-basic-help/#findComment-10652137
Share on other sites

Link to post
Share on other sites

3 minutes ago, CmzPlusHardware said:

I've heard of Await, but I am struggling on how to use it. I've seen it in other examples, but don't quite know how to use it in my case. 

 

(Note: My VB Skills is a somewhat moderate) 

My VB skills are non existent, but I can at least point you in a direction :P Microsoft Docs has a tutorial on it that should be helpful. (Link)

Link to comment
https://linustechtips.com/topic/855319-visual-basic-help/#findComment-10652169
Share on other sites

Link to post
Share on other sites

3 minutes ago, Rechdan said:

Hello there, I strongly recommend you looking out C#, it's pretty much the same as VB (for me) but more advanced.

And there should also be better help resources for C# (Even though they both are part of Microsoft's CLI, C# gets more love from the community, especially as it is treated as a cleaner version of Java)

Link to comment
https://linustechtips.com/topic/855319-visual-basic-help/#findComment-10652659
Share on other sites

Link to post
Share on other sites

57 minutes ago, tjcater said:

And there should also be better help resources for C# (Even though they both are part of Microsoft's CLI, C# gets more love from the community, especially as it is treated as a cleaner version of Java)

Yes, and I'm a C# developer, so I strongly recommend it! If you need any help with that, just send me a message and I will help you for sure! :D

Link to comment
https://linustechtips.com/topic/855319-visual-basic-help/#findComment-10652871
Share on other sites

Link to post
Share on other sites

1 hour ago, Rechdan said:

Yes, and I'm a C# developer, so I strongly recommend it! If you need any help with that, just send me a message and I will help you for sure! :D

Is it fairly similar? Here is what I am trying to do. I want to create a Game Console Like Interface that can be controlled via a controller. I would like to use this to launch games 

 

(I understand other things like this exist, I kinda just want to make my own)

Tech enthusiast and CS Student

 

 

 

 

 

Link to comment
https://linustechtips.com/topic/855319-visual-basic-help/#findComment-10653134
Share on other sites

Link to post
Share on other sites

The WebClient class has a DownloadFileCompleted event you can use. You can "Handles" it just like you did with the DownloadProgressChanged event in your code snippet, or you can use the "AddHandler" like in the link example (just don't do both or the event will be triggered twice).

Link to comment
https://linustechtips.com/topic/855319-visual-basic-help/#findComment-10653332
Share on other sites

Link to post
Share on other sites

7 hours ago, CmzPlusHardware said:

Is it fairly similar? Here is what I am trying to do. I want to create a Game Console Like Interface that can be controlled via a controller. I would like to use this to launch games 

 

(I understand other things like this exist, I kinda just want to make my own)

Yes, they look the same but with a slightly different syntax.

Link to comment
https://linustechtips.com/topic/855319-visual-basic-help/#findComment-10654100
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×