【发布时间】:2015-06-26 08:44:52
【问题描述】:
我正在为我的作业制作一个机器人,它使用代理浏览网站。我有一个名为“浏览”的字段,它可以让我浏览代理文件并读入一个数组并显示来自计数器的代理总数。我被困在下面。以下是当前正在使用的代码。请帮忙
变量 proxyArray 之前已被使用并赋值。一个空 运行时可能会导致引用异常。
代码
Private Sub browserProxy_Click(sender As Object, e As EventArgs) Handles browserProxy.Click
Dim myStream As Stream = Nothing
Dim selectedFile As String
Dim openFileDialog1 As New OpenFileDialog()
Dim proxyArray() As String
Dim totalProxy As Integer
openFileDialog1.InitialDirectory = "C:\"
openFileDialog1.Filter = "Text File (*.txt)|*.txt"
openFileDialog1.FilterIndex = 1
openFileDialog1.RestoreDirectory = False
If openFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
selectedFile = String.Format(openFileDialog1.FileName)
Dim objreader As New System.IO.StreamReader(selectedFile)
i = 0
Do While Not objreader.EndOfStream
proxyArray(i) = objreader.ReadLine
i += 1
Loop
totalProxy = i
objreader.Close()
End If
End Sub
这会在运行时弹出。
【问题讨论】:
标签: vb.net