Visual Basic : Sélectionner une ligne dans une TextBox

Bonjour, je ne sais pas si je suis dans la bonne section mais j'utilise Visual Basic 2010 et j'ai besoin d'aide pour un logiciel, qui utilise un proxy, mais il doit prendre une ligne au hasard dans une TextBox multiligne....

Voici un screen: http://hpics.li/bc96db9

En fait, je sais trés bien comment faire pour le proxy, mais je sais pas comment faire pour qu'il sélectionne une ligne au hasard parmis les ~ 2,000 lignes qu'il y a.

Merci à celui qui m'aidera, ou celle, ça me sera TRéS utile, sur tout mes logiciels d'ailleurs ;)
PS: Ce qui ne savent pas comment faire pour les proxys, venez MP je serais ravi de vous expliquer :)

Bonne nuit, merci d'avance

2 réponses

  1. Bonjour, merci beaucoup de ta réponse, et effectivement mon proxy doit sélectionner parmi la longue textbox une ligne au hasard, ou il y aura une ligne Ip:Port, ca je sais comment faire, merci beaucoup,

    je te tiens informé ;)
    0
    1. Contributeur
      Bonjour, par séléctionner, tu entends juste récupérer une ligne dans un String, ou mettre le texte désigné en surbillance?
      Je considère que le premier cas est plus adapté:
      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))
      1
      1. Salut, malheureusement j'ai 2 erreurs:

        'Generator' n'est pas déclaré. Il peut être inaccessible en raison de son niveau de protection.
        de cette ligne : Dim selection As String = lignes(Generator.Next(0, lignes.Length))

        'arg' n'est pas déclaré. Il peut être inaccessible en raison de son niveau de protection.

        de cette ligneDim lignes() As String = TextBox1.Text.Split(arg, StringSplitOptions.None)

        .... tu peux m'aider stp? :/
        0
      2. Contributeur
        Oups, c'est car j'ai traduit un bout de code anglais à la base.
        Remplace "arg" par "separateurs", et "Generator" par "hasard"
        0
      3. ok merci mdr, tu gère, je teste ca ;)
        0
      4. Re, j'ai ce 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


        Ca pour le proxy ok, mais l'autre 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


        Ca me prend bizarrement toujours la première ligne, :/
        0