Reputation: 46
Problem 1: Can't Use a CheckBox as a String Variable
Dim link As String = CheckBox1.Checked
Problem 2: Can't figure out how to write the results of my code to my textbox:
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
If (Not RawPaste.Text = Nothing) Then
Dim r As HttpWebRequest = HttpWebRequest.Create(link)
r.UserAgent = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.69 Safari/537.36"
r.KeepAlive = True
Dim re As HttpWebResponse = r.GetResponse()
Dim src As String = New StreamReader(re.GetResponseStream()).ReadToEnd()
Dim rows As String() = GetBetweenAll(src, "<tr>", "</tr>")
Dim tds As New List(Of String)
Dim dones As New List(Of String)
Dim sb As New StringBuilder
For Each s As String In rows
If (Not s = rows(0) And s.Contains("<td>") And s.Contains("</td>")) Then
Dim td As String() = GetBetweenAll(s, "<td>", "</td>")
Dim ip As String = td(0)
Dim port As String = td(1)
dones.Add(ip & ":" & port)
sb.Append(ip & ":" & port) ' or dones.Count-1, but i dont
' know what it is List? Array?
End If
Next
RawPaste.Text = sb.ToString
Progress.Value = 100
End If
End Sub
Upvotes: 0
Views: 370
Reputation: 38905
1) of course not: strings are text and checkboxes are objects...you probably want this:
Dim link As String = CheckBox1.Text
if you were really after the checkstate, set it in a IF block, or try
Dim link As String = CheckBox1.Checked.ToString ' will be 'True' or 'False'
Final Edit: With the poorly named CheckBox1
now revealed to be a CheckedLISTBOX, you have to get the text from the one selected, if there is one:
Dim link as string
If CheckedListBox.CheckedItems.Count THen ' check for at least one checked
link = CheckedListBox.CheckedItems(0).ToString
End if
2) try this:
Using sw As New StreamWriter(RawPaste.Text)
For Each s As String In dones
sw.WriteLine(s) //<- I want to replace that so it writes to a textbox
TextBoxToWriteTo.Text &= s
Next
End Using
I am not sure of the relationship between RawPaste and dones, but that loop should be able to be optomized:
EDIT:
YOu dont need a stream writer at all, just append the text as you process:
Dim sb as New StringBuilder
For Each s As String In rows
If (Not s = rows(0) And s.Contains("<td>") And s.Contains("</td>")) Then
Dim td As String() = GetBetweenAll(s, "<td>", "</td>")
Dim ip As String = td(0)
Dim port As String = td(1)
dones.Add(ip & ":" & port)
sb.Append (ip & ":" & port) ' or dones.Count-1, but i dont
' know what it is List? Array?
End If
Next
RawPaste.Text = sb.ToString
...and if that was the whole point of dones - to accumulate for the textbox, it is not needed anymore
Upvotes: 1