我正在爲我的作業製作一個bot,它使用代理來瀏覽網站。我有一個名爲「Browse」的字段,它讓我瀏覽代理文件並讀入一個數組,並顯示來自計數器的代理總數。我被困在這裏。以下是我目前使用的代碼。請幫忙變量已被使用過,並被賦值
變量proxyArray已經在之前被使用過並且被分配了一個值。在運行時可能會導致引用異常null 。
代碼
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
運行時該彈出。