我正在尝试编写下载管理器代码,但收到此错误: '保存'没有宣布。由于其保护级别,它可能无法访问
这是我的代码:
Imports System.Net
Public Class Form1
Private WithEvents httpclient As webClient
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
ListBox1.Items.Add(TextBox1.Text)
TextBox1.Clear()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SaveFileDialog1.ShowDialog()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Try
httpclient = New WebClient
Dim total As Integer = ListBox1.Items.Count
Dim current As Integer = -1
While current < total
ListBox1.SelectedIndex = current + 1
Dim download As String = ListBox1.SelectedItem
httpclient.DownloadFileAsync(New Uri(download), save)
Label3.Text = "Current Status: Downloading:..."
Do While httpclient.IsBusy
Application.DoEvents()
Loop
current = current + 1
End While
Catch ex As Exception
ListBox1.Items.Clear()
End Try
End Sub
End Class
答案 0 :(得分:1)
DownloadFileAsync
需要2个参数。第一个是要下载的文件的URL,第二个是保存文件的本地位置。您关注的教程可能会在代码中的某处设置变量Save
。
要实现此目的,您可以将其替换为"C:\Test.txt"
之类的内容,以将其下载到该位置或定义变量Save
并将其值设置为您想要的位置保存文件。
使用现有代码,要允许用户选择保存位置,您需要进行以下更改。在Save
行:
Public Class Form1
变量私有
Private Save as string
然后在你的Button1_Click
事件中,它看起来应该更像这样:
If SaveFileDialog1.ShowDialog() = DialogResult.OK Then
Save = SaveFileDialog1.FileName
End If
答案 1 :(得分:-1)
dist/GET.app.lambda.js