Déclaration de contrôle crée par code

Résolu
scoob79 Messages postés 27 Date d'inscription mercredi 20 janvier 2010 Statut Membre Dernière intervention 5 septembre 2018 - 14 août 2018 à 11:53
scoob79 Messages postés 27 Date d'inscription mercredi 20 janvier 2010 Statut Membre Dernière intervention 5 septembre 2018 - 16 août 2018 à 23:30
Salut @ tts,

j'ai un petit soucis, j'ai créé un contrôle type textbox (text1), tant que je suis dans la sub qu'il la créée pas de soucis j'ai accès au contrôle, par contre lorsque je passe dans une autre sub il ne le reconnait plus.

Sub où il est créé :

   Public Sub ComboBox3_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox3.SelectedIndexChanged
        Dim Fichier As New StreamReader("c:\temp\ConfCompar.ini"), Ligne As String, Instruction As String, Todo As String
        Do
            Ligne = Fichier.ReadLine()

            If Ligne <> "" Then
                If InStr(Ligne, "{") = 0 Or InStr(Ligne, "{") = 0 Or InStr(Ligne, "{") = 0 Then MsgBox("Erreur dans le fichier de configuration.", vbExclamation) : End
            End If

            If InStr(Ligne, ComboBox3.Text) > 0 Then
                Instruction = Ligne.Substring(InStr(Ligne, "{"))
                Champ = Instruction.Substring(0, InStr(Instruction, "|") - 1)
                Todo = Instruction.Substring(InStr(Instruction, "|"))
                Todo = Todo.Substring(0, Len(Todo) - 1)
            End If

            If Champ = "text" Then
                Dim text1 As New TextBox, label1 As New Label, bouton1 As New Button
                TabControl1.TabPages(1).Controls.Add(text1)
                TabControl1.TabPages(1).Controls.Add(label1)
                TabControl1.TabPages(1).Controls.Add(bouton1)
                label1.Location = New Drawing.Point(340, 22)
                label1.Text = "Recherche"
                text1.Location = New Drawing.Point(400, 20)
                text1.Width = text1.Width + 150
                bouton1.Location = New Drawing.Point(660, 20)
                bouton1.Height = 20
                bouton1.Text = "Lancer !!!"
                AddHandler bouton1.Click, AddressOf rech
                Exit Do

            End If
        Loop Until Ligne Is Nothing
    End Sub


Sub où je l'appel :

    Public Sub rech()
        Dim Serveur As New StreamReader("c:\temp\serveur.ini")
        Dim Nom As String, Ligne As String, Hier As Date, Res As Integer, Section As String, Cle As String, Valeur As String
        DataGridView5.Rows.Clear()
        DataGridView5.Columns.Clear()
        DataGridView5.Columns.Add(0, "Champ")
        DataGridView5.Rows.Add()
        Do
            Nom = Serveur.ReadLine
            Hier = Today.AddDays(-1)
            Section = ComboBox3.Text.Substring(0, InStr(ComboBox3.Text, "\") - 1)
            Cle = ComboBox3.Text.Substring(InStr(ComboBox3.Text, "\"))

            If My.Computer.FileSystem.FileExists("c:\temp\audit_" & Nom & "_" & Replace(Hier, "/", "") & ".txt") Then
                Dim Audit As New StreamReader("c:\temp\audit_" & Nom & "_" & Replace(Hier, "/", "") & ".txt")
                Do
                    Do
                        Ligne = Audit.ReadLine
                        If InStr(Ligne, Section) > 0 Then Exit Do
                    Loop Until Ligne Is Nothing

                    Do
                        Ligne = Audit.ReadLine
                        If InStr(Ligne, Cle) > 0 Then
                            Valeur = Ligne.Substring(InStr(ComboBox3.Text, "="))
                                If InStr(Valeur, text1.value) > 0 Then
                                Res += 1
                                DataGridView5.Columns.Add(0, Nom)
                                DataGridView5.Rows(0).Cells(0).Value = Cle
                                DataGridView5.Rows(0).Cells(Res).Value = Ligne.Substring(InStr(Ligne, "="))
                            End If
                        End If
                    Loop Until Ligne Is Nothing
                Loop Until Ligne Is Nothing
            End If
        Loop Until Nom Is Nothing
    End Sub


Merci pour vos conseils.

2 réponses

Whismeril Messages postés 18291 Date d'inscription mardi 11 mars 2003 Statut Contributeur Dernière intervention 24 mars 2023 622
14 août 2018 à 12:27
Bonjour

c'est une question de portée, quelle que soit la variable

QuelqueChose
       Dim toto as int 'toto est accessible partout entre QuelqueChose et End QuelqueChose

       Sub TrucMuche
              'toto et tutu sont accessibles ici
              Dim tata as string
       End Sub

       Sub Bidule
              'toto et tutu sont accessibles ici
              'tata n'est pas accessible ici
       End Sub

      Dim tutu as string
End QuelqueChose

1
scoob79 Messages postés 27 Date d'inscription mercredi 20 janvier 2010 Statut Membre Dernière intervention 5 septembre 2018
14 août 2018 à 12:43
Merci pour ta réponse effectivement c'était bien le cas je suis vraiment c** ou tellement dans mon code que j'en oublie les principe de base. Je me doutais bien que c'était au niveau de la portée mais à regarder trop mon code sans prendre de recule ... Arfff

Encore merci pour se regarde neuf. ;)
0
Whismeril Messages postés 18291 Date d'inscription mardi 11 mars 2003 Statut Contributeur Dernière intervention 24 mars 2023 622
14 août 2018 à 13:06
1
scoob79 Messages postés 27 Date d'inscription mercredi 20 janvier 2010 Statut Membre Dernière intervention 5 septembre 2018
16 août 2018 à 23:30
fait merci encore
0
Rejoignez-nous