-3

リストボックスにIPアドレスがあり、リストボックスの項目をテキストボックスに転送する方法をすでに取得しているこのプロジェクトに取り組んでいますが、ボタンで自分自身を変更するにはIPが必要です。

たとえば、次の 3 つの IP アドレスがあります。

  • 123.456.78
  • 891.23.45.6
  • 789.123.12

テキストボックス内の現在の IP アドレスは 123.456.78 ですが、ボタンをクリックすると 2 行目である 891.23.45.6 に変更され、テキストボックス内でのみ可能です (123.456.78 が横に押し出されるのとは異なります)。

それが私が必要とするコードです。

そのすべては、次のような 1 つのボタンの下に配置されます。

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '*Grabbing our proxy text from our online server (this way we can keep updating our proxies).
    Dim Str As System.IO.Stream
    Dim srRead As System.IO.StreamReader
    Try
        ' make a Web request
        Dim req As System.Net.WebRequest = System.Net.WebRequest.Create("https://dl.dropbox.com/somethingOrOther")
        Dim resp As System.Net.WebResponse = req.GetResponse
        Str = resp.GetResponseStream
        srRead = New System.IO.StreamReader(Str)
        ' read all the text 
        TextBox2.Text = srRead.ReadToEnd
    Catch ex As Exception
        TextBox2.Text = "Unable to download content"
    Finally
        '  Close Stream and StreamReader when done
        srRead.Close()
        Str.Close()
    End Try

    ' Assign string to reference.
    Dim value1 As String = TextBox2.Text


    ' Replace word with another word.
    Dim value2 As String = value1.Replace("<br>", vbNewLine)
    TextBox2.Text = value2
    ListBox1.Items.Add(TextBox2.Text)

    '*Now , we're taking our fresh proxies in the textbox and moving them into our listbox.

    ListBox1.Items.AddRange(TextBox2.Text.Split(vbNewLine))
End Sub

誰かが私を助けることができますか?

4

2 に答える 2

0

このコード:

'Assign string to reference.
Dim value1 As String = TextBox2.Text


'Replace word with another word.
Dim value2 As String = value1.Replace("<br>", vbNewLine)
TextBox2.Text = value2
ListBox1.Items.Add(TextBox2.Text)

'*Now , we're taking out fresh proxies in the textbox and moving them into our listbox

ListBox1.Items.AddRange(TextBox2.Text.Split(vbNewLine))

機能的には、次のコードと同等です。

TextBox2.Text = TextBox2.Text.Replace("<br>", vbNewLine)
ListBox1.Items.Add(TextBox2.Text)
ListBox1.Items.AddRange(TextBox2.Text.Split(vbNewLine))

すでにすべてのs を要素に置き換えているため、行ListBox1.Items.AddRange(TextBox2.Text.Split(vbNewLine))は目的の動作をしません(ちなみに、これは XHTML では形式が正しくありません... 代わりに ... にする必要があります)。vbNewLine<br><br />

機密情報 (ドロップボックスの URL など) を一般的な情報に置き換えて、button.click ハンドラー全体を投稿できる場合は、より適切な支援を提供できる可能性があります。

アップデート:

フォームのマークアップが次のようになっているとします。

<asp:ListBox ID="ListBox1" runat="server" SelectionMode="Single" AutoPostBack="true"></asp:ListBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Get Proxies" />

ハンドラーでこれらを試してください:

Private Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
    Dim req As System.Net.WebRequest = Nothing
    Dim resp As System.Net.WebResponse = Nothing
    Dim Str As System.IO.Stream = Nothing
    Dim srRead As System.IO.StreamReader = Nothing
    Dim responseText As String = String.Empty
    Dim proxies() As String = Nothing
    Dim list As ArrayList = Nothing
    Dim ipAddress As String = String.Empty
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '*Grabbing our proxy text from our online server (this way we can keep updating our proxies).
    Try
        ' make a Web request
        req = System.Net.WebRequest.Create("https://dl.dropbox.com/somethingOrOther")
        resp = req.GetResponse
        Str = resp.GetResponseStream
        srRead = New System.IO.StreamReader(Str)
        ' read all the text 
        responseText = srRead.ReadToEnd
    Catch ex As Exception
        responseText = "Unable to download content"
    Finally
        ' Close Stream and StreamReader when done
        srRead.Close()
        Str.Close()
    End Try

    '*Now , we're taking our fresh proxies in the textbox and moving them into our listbox.
    proxies = responseText.Split(vbNewLine)
    For Each ipAddress In proxies
        list.Add(New ListItem(ipAddress))
    Next

    ListBox1.Items.AddRange(list.ToArray(GetType(ListItem)))
End Sub

Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
    If ListBox1.SelectedIndex > -1 Then
        TextBox2.Text = ListBox1.SelectedValue
    End If
End Sub
于 2012-10-06T13:35:02.977 に答える
0

ListBox.SelectedIndex物件をお試しください。

特定のインデックスの値を確認する必要がある場合は、ListBox.Itemsプロパティを使用できます。

リストボックスを反復処理する必要がある場合 (たとえば、特定の値を探すため)、次のListBox.Items.Countプロパティを利用できます。

For l_currentIndex As Integer = 0 to MyListBox.Items.Count - 1
    If CStr(MyListBox.Items(l_currentIndex)) = "MyExpectedValue" Then
        MyListBox.SelectedInex = l_currentIndex
        Exit ' Exit For Loop
    End If
Next
于 2012-10-06T13:25:08.743 に答える