Visual Basic: Select a line in a TextBox

Hello, I’m not sure if I’m in the right section but I’m using Visual Basic 2010 and I need help for a software that uses a proxy, but it must take a random line from a multiline TextBox....

Here’s a screenshot: http://hpics.li/bc96db9

In fact, I know very well how to do the proxy, but I don’t know how to make it select a random line among the ~ 2,000 lines there are.

Thanks to anyone who will help, or her, that will be VERY useful to me for all my software anyway ;)
PS: For those who don’t know how to do proxies, come to my PM I’d be happy to explain :)

Good night, thanks in advance

Configuration: Windows 7 / Chrome 28.0.1500.95

2 answers

  1. Hello, thank you very much for your reply, and indeed my proxy has to select randomly a line from the long textbox, where there will be a line Ip:Port, I know how to do that, thank you very much,

    I’ll keep you posted ;)
    0
    1. Contributor
      Hello, by selection, do you mean just retrieving a line in a String, or highlighting the designated text?
      I consider the first case to be more suitable:
      Dim separateurs() As String = {vbCrLf, vbLf} 'Les caractères de reour à la ligne Dim lignes() As String = TextBox1.Text.Split(arg, StringSplitOptions.None) Dim hasard As System.Random = New System.Random() Dim selection As String = lignes(Generator.Next(0, lignes.Length))

      --
      from human import idiocy
      del idiocy
      1
      1. Hi, unfortunately I have 2 errors:

        'Generator' is not declared. It may be inaccessible due to its protection level.
        from this line: Dim selection As String = lignes(Generator.Next(0, lignes.Length))

        'arg' is not declared. It may be inaccessible due to its protection level.

        from this line: Dim lignes() As String = TextBox1.Text.Split(arg, StringSplitOptions.None)

        .... can you help me please? :/
        0
      2. Contributor
        Oops, it's because I translated a bit of code into English originally.
        Replace "arg" with "separateurs", and "Generator" with "hasard"
        0
      3. Okay, thanks lol, you handle it, I’m testing this ;)
        0
      4. Here is the English translation of your message, preserving the code structure and emotion: Re, I have this code:

        #Region "Using Proxy" <Runtime.InteropServices.DllImport("wininet.dll", SetLastError:=True)> _ Private Shared Function InternetSetOption(ByVal hInternet As IntPtr, ByVal dwOption As Integer, ByVal lpBuffer As IntPtr, ByVal lpdwBufferLength As Integer) As Boolean End Function Public Structure Struct_INTERNET_PROXY_INFO Public dwAccessType As Integer Public proxy As IntPtr Public proxyBypass As IntPtr End Structure Private Sub UseProxy(ByVal strProxy As String) Const INTERNET_OPTION_PROXY As Integer = 38 Const INTERNET_OPEN_TYPE_PROXY As Integer = 3 Dim struct_IPI As Struct_INTERNET_PROXY_INFO struct_IPI.dwAccessType = INTERNET_OPEN_TYPE_PROXY struct_IPI.proxy = Marshal.StringToHGlobalAnsi(strProxy) struct_IPI.proxyBypass = Marshal.StringToHGlobalAnsi("local") Dim intptrStruct As IntPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(struct_IPI)) Marshal.StructureToPtr(struct_IPI, intptrStruct, True) Dim iReturn As Boolean = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY, intptrStruct, System.Runtime.InteropServices.Marshal.SizeOf(struct_IPI)) End Sub #End Region


        This for the proxy is okay, but the other code:

        If Not TextBox1.Text = "" Then If CheckBox1.Checked = True Then If TextBox2.Text = "" Then Dim info = New System.Media.SoundPlayer(My.Resources.info) info.Play() MsgBox("Veuillez choisir une liste de proxys valide !", MsgBoxStyle.Information, "Liste de proxys invalides") End If If Not TextBox2.Text = "" Then Dim separateurs() As String = {vbCrLf, vbLf} 'Les caractères de reour à la ligne Dim lignes() As String = TextBox2.Text.Split(separateurs, StringSplitOptions.None) Dim hasard As System.Random = New System.Random() Dim selection As String = lignes(hasard.Next(0, lignes.Length)) UseProxy(lignes(hasard.Next(0, lignes.Length))) WebBrowser1.Navigate("monip.org") End If End If End If


        It oddly always takes the first line, :/
        0