无法写入TextBox +无法将Checkbox用作字符串变量

时间:2013-11-21 00:04:08

标签: string hyperlink textbox vb.net

问题1:不能将CheckBox用作字符串变量

Dim link As String = CheckBox1.Checked

问题2:无法弄清楚如何将我的代码结果写入文本框:

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

1 个答案:

答案 0 :(得分:1)

1)当然不是:字符串是文本,复选框是对象......你可能想要这个:

Dim link As String = CheckBox1.Text

如果您真的在检查状态之后,请将其设置在IF块中,或尝试

Dim link As String = CheckBox1.Checked.ToString   ' will be 'True' or 'False'

最终编辑:由于名称不佳的CheckBox1现在显示为CheckedLISTBOX,您必须从所选的文本中获取文本,如果有的话:

Dim link as string
If CheckedListBox.CheckedItems.Count THen       ' check for at least one checked
   link = CheckedListBox.CheckedItems(0).ToString
End if

2)试试这个:

    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

我不确定RawPaste和dones之间的关系,但该循环应该能够被优化:

编辑:

根本不需要流编写器,只需在处理时附加文本:

    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

......如果那是完整的点 - 为文本框积累,就不再需要了