I'm trying to make a list of file extensions from a website, but my listbox wont populate with them from Regex matches. I know the httpRequest works, because the websites source code lists in a richtextbox for viewing. Running the code below doesn't give any errors, even when I edit the code to work under Option strict.
Can someone explain to me maybe with an example as to why my listbox wont populate. Thanks!
With Option Strict On:
Can someone explain to me maybe with an example as to why my listbox wont populate. Thanks!
Code:
Imports System.Text.RegularExpressions
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("http://filext.com/alphalist.php?extstart=^A")
Dim response As System.Net.HttpWebResponse = request.GetResponse
Dim sr As System.IO.StreamReader = New System.IO.StreamReader(response.GetResponseStream())
Dim resourcecode As String = sr.ReadToEnd
RichTextBox1.Text = resourcecode
Dim r As New System.Text.RegularExpressions.Regex("<td width=""120"">""""<a href=""http://filext.com/file-extension/.*"" target=""_blank"">"""".*""</a>""</td>")
Dim matches As MatchCollection = r.Matches(resourcecode)
For Each itemcode As Match In matches
ListBox1.Items.Add(itemcode.Value.Split("""").GetValue(9))
Next
End Sub
End Class
With Option Strict On:
Code:
Option Strict On
Imports System.Text.RegularExpressions
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim request As System.Net.HttpWebRequest = CType(System.Net.HttpWebRequest.Create("http://filext.com/alphalist.php?extstart=^A"), Net.HttpWebRequest)
Dim response As System.Net.HttpWebResponse = CType(request.GetResponse, Net.HttpWebResponse)
Dim sr As System.IO.StreamReader = New System.IO.StreamReader(response.GetResponseStream())
Dim resourcecode As String = sr.ReadToEnd
RichTextBox1.Text = resourcecode
Dim r As New System.Text.RegularExpressions.Regex("<td width=""120"">""""<a href=""http://filext.com/file-extension/.*"" target=""_blank"">"""".*""</a>""</td>")
Dim matches As MatchCollection = r.Matches(resourcecode)
For Each itemcode As Match In matches
ListBox1.Items.Add(itemcode.Value.Split(CChar("""")).GetValue(9))
Next
End Sub
End Class