溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

VB.NET下載程序?qū)崿F(xiàn)代碼怎么編寫

發(fā)布時間:2021-10-27 18:04:39 來源:億速云 閱讀:124 作者:柒染 欄目:編程語言

今天就跟大家聊聊有關(guān)VB.NET下載程序?qū)崿F(xiàn)代碼怎么編寫,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。

對于VB.NET語言的應(yīng)用來說,其中有很多小技巧值得我們?nèi)フ莆?,來充?shí)我們的開發(fā)經(jīng)驗(yàn),以提高編程效率。比如VB.NET下載程序的實(shí)現(xiàn),就是其中一個很有用的編程技巧,能幫助我們很好的解決開發(fā)中所遇到的相關(guān)問題。

VB.NET下載程序代碼示例:

  1. Public Shared fpath As String  

  2. Dim fsize As Long  

  3. Private Sub Button1_Click(ByVal sender As System.Object, 
    ByVal e As System.EventArgs) Handles Button1.Click  

  4. Try  

  5. If Me.TextBox1.Text = "http://" Then  

  6. MessageBox.Show("請輸入正確的URL!")  

  7. Return  

  8. End If  

  9. Dim urld As String  

  10. Dim i As Integer  

  11. Dim dfile As New WebClient  

  12. Me.SaveFileDialog1.ShowDialog()  

  13. fpath = SaveFileDialog1.FileName  

  14. Label3.Text = "文件保存在:" & fpath  

  15. urld = Me.TextBox1.Text  

  16. Me.Timer1.Enabled = True 

  17. dfile.DownloadFile(urld, fpath.Substring
    (Me.TextBox1.Text.ToString.LastIndexOf("."), 4))  

  18. Me.Timer1.Enabled = False 

  19. Catch ex As Exception  

  20. MessageBox.Show(ex.Message)  

  21. Return  

  22. Application.Exit()  

  23. End Try  

  24. End Sub 

  1. Private Sub Timer1_Tick(ByVal sender As System.Object, 
    ByVal e As System.EventArgs) Handles Timer1.Tick  

  2. Dim th3 As New th2  

  3. Dim tt As New System.Threading.Thread(AddressOf th3.timeth) 

  4. '實(shí)例化線程類   

  5. tt.Start() '啟動線程   

  6. Label2.Text = th3.downk '顯示下載文件的大小   

  7. '進(jìn)行計(jì)算下載速度   

  8. Static k As Integer  

  9. Dim p, downspeed  

  10. p = k 

  11. k = p + 1  

  12. p = k 

  13. Dim form As New DownLoad  

  14. Dim fileinfo As New System.IO.FileInfo(form.fpath)  

  15. downspeed = fileinfo.Length()  

  16. downspeeddownspeed = downspeed / p  

  17. Label4.Text = "當(dāng)前下載速度是" & downspeed & "k/m"  

  18. End Sub  

  19. End Class  

  20. Public Class th2  

  21. Public Shared downk As String  

  22. Dim form As New DownLoad  

  23. Dim fileinfo As New System.IO.FileInfo(form.fpath)  

  24. Dim fsize As Long  

  25. Public Sub timeth()  

  26. If fileinfo.Exists = True Then  

  27. fsize = fileinfo.Length()  

  28. downk = "以下載文件" & fsize & "k"  

  29. End If  

  30. End Sub  

  31. End Class 

看完上述內(nèi)容,你們對VB.NET下載程序?qū)崿F(xiàn)代碼怎么編寫有進(jìn)一步的了解嗎?如果還想了解更多知識或者相關(guān)內(nèi)容,請關(guān)注億速云行業(yè)資訊頻道,感謝大家的支持。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI