IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB.NET Discussion :

Boucles et listbox [Débutant]


Sujet :

VB.NET

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Homme Profil pro
    Inscrit en
    Octobre 2011
    Messages
    135
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Octobre 2011
    Messages : 135
    Par défaut Boucles et listbox
    Bonjour,

    Je travaille actuellement sur une application pour gérer des Quizz. Chacun d'eux comprend 10 Questions avec pour chacune d'elle 4 propositions de réponse, la réponse et enfin d'éventuelles informations pour expliquer la réponse.

    Pour ce faire j'ai créé 1 TextBox pour le nom du Quizz, 10 TextBox (1 par Question), 4 TextBox par questions pour les 4 propositions de réponse, 1 TextBox par questions pour la réponse exacte, 2 Label (Un pour indique s'il y a ou non une information et un pour l'information en elle même)

    Les données de l'ensemble de ces TextBox sont enregistrées dans des ComboBox et des ListBox. Le nom du Quizz est enregistré dans la CombBox, les questions dans une ListeBox, les propositions 1, 2, 3 et 4 chacune dans des listbox distinctes, les réponses dans une autre ListBox et enfin les mentions d'informations et les information dans les 2 dernières ListBox.

    Ce qui fait que dans la ComboBox j'ai Une entrée par Quizz, et dans les ListBox 10 entrées Par Quizz.

    Pour remplir mes TextBox et mes Label, j'utiliste le code suivant qui fonctionne parfaitement bien pour l'index "0" de la Cb_QuizzList (ComboBox avec le nom du quizz) :


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    Private Sub Cb_ListeQuizz_SelectedIndexChanged(sender As Object, e As EventArgs) Handles Cb_ListeQuizz.SelectedIndexChanged
            'Charge le quizz en mémoire dans les boites Text
            Dim Index1 As Integer = -1
            For a = 0 To 9
                Index1 = Index1 + 1
                Lb_QuizzQuestion.SelectedIndex = Cb_ListeQuizz.SelectedIndex + Index1
                Lb_QuizzProposition1.SelectedIndex = Cb_ListeQuizz.SelectedIndex + Index1
                Lb_QuizzProposition2.SelectedIndex = Cb_ListeQuizz.SelectedIndex + Index1
                Lb_QuizzProposition3.SelectedIndex = Cb_ListeQuizz.SelectedIndex + Index1
                Lb_QuizzProposition4.SelectedIndex = Cb_ListeQuizz.SelectedIndex + Index1
                Lb_QuizzReponse.SelectedIndex = Cb_ListeQuizz.SelectedIndex + Index1
                Lb_QuizzInfo.SelectedIndex = Cb_ListeQuizz.SelectedIndex + Index1
                Lb_QuizzInfo1.SelectedIndex = Cb_ListeQuizz.SelectedIndex + Index1
                If Index1 = 0 Then
                    Tb_Question1.Text = Lb_QuizzQuestion.Text
                    Tb_P11.Text = Lb_QuizzProposition1.Text
                    Tb_P12.Text = Lb_QuizzProposition2.Text
                    Tb_P13.Text = Lb_QuizzProposition3.Text
                    TB_P14.Text = Lb_QuizzProposition4.Text
                    Tb_Rep1.Text = Lb_QuizzReponse.Text
                    Lab_QuizzInfo1.Text = Lb_QuizzInfo.Text
                    Lab_QuizzInfo11.Text = Lb_QuizzInfo1.Text
                End If
                If Index1 = 1 Then
                    Tb_Question2.Text = Lb_QuizzQuestion.Text
                    Tb_P21.Text = Lb_QuizzProposition1.Text
                    Tb_P22.Text = Lb_QuizzProposition2.Text
                    Tb_P23.Text = Lb_QuizzProposition3.Text
                    Tb_P24.Text = Lb_QuizzProposition4.Text
                    Tb_Rep2.Text = Lb_QuizzReponse.Text
                    Lab_QuizzInfo2.Text = Lb_QuizzInfo.Text
                    Lab_QuizzInfo20.Text = Lb_QuizzInfo1.Text
                End If
                If Index1 = 2 Then
                    Tb_Question3.Text = Lb_QuizzQuestion.Text
                    Tb_P31.Text = Lb_QuizzProposition1.Text
                    Tb_P32.Text = Lb_QuizzProposition2.Text
                    Tb_P33.Text = Lb_QuizzProposition3.Text
                    Tb_P34.Text = Lb_QuizzProposition4.Text
                    Tb_Rep3.Text = Lb_QuizzReponse.Text
                    Lab_QuizzInfo3.Text = Lb_QuizzInfo.Text
                    Lab_QuizzInfo30.Text = Lb_QuizzInfo1.Text
                End If
                If Index1 = 3 Then
                    Tb_Question4.Text = Lb_QuizzQuestion.Text
                    Tb_P41.Text = Lb_QuizzProposition1.Text
                    Tb_P42.Text = Lb_QuizzProposition2.Text
                    Tb_P43.Text = Lb_QuizzProposition3.Text
                    TB_P44.Text = Lb_QuizzProposition4.Text
                    Tb_Rep4.Text = Lb_QuizzReponse.Text
                    Lab_QuizzInfo4.Text = Lb_QuizzInfo.Text
                    Lab_QuizzInfo40.Text = Lb_QuizzInfo1.Text
                End If
                If Index1 = 4 Then
                    Tb_Question5.Text = Lb_QuizzQuestion.Text
                    Tb_P51.Text = Lb_QuizzProposition1.Text
                    Tb_P52.Text = Lb_QuizzProposition2.Text
                    Tb_P53.Text = Lb_QuizzProposition3.Text
                    Tb_P54.Text = Lb_QuizzProposition4.Text
                    Tb_Rep5.Text = Lb_QuizzReponse.Text
                    Lab_QuizzInfo5.Text = Lb_QuizzInfo.Text
                    Lab_QuizzInfo50.Text = Lb_QuizzInfo1.Text
                End If
                If Index1 = 5 Then
                    Tb_Question6.Text = Lb_QuizzQuestion.Text
                    Tb_P61.Text = Lb_QuizzProposition1.Text
                    Tb_P62.Text = Lb_QuizzProposition2.Text
                    Tb_P63.Text = Lb_QuizzProposition3.Text
                    Tb_P64.Text = Lb_QuizzProposition4.Text
                    Tb_Rep6.Text = Lb_QuizzReponse.Text
                    Lab_QuizzInfo6.Text = Lb_QuizzInfo.Text
                    Lab_QuizzInfo60.Text = Lb_QuizzInfo1.Text
                End If
                If Index1 = 6 Then
                    Tb_Question7.Text = Lb_QuizzQuestion.Text
                    Tb_P71.Text = Lb_QuizzProposition1.Text
                    Tb_P72.Text = Lb_QuizzProposition2.Text
                    Tb_P73.Text = Lb_QuizzProposition3.Text
                    Tb_P74.Text = Lb_QuizzProposition4.Text
                    Tb_Rep7.Text = Lb_QuizzReponse.Text
                    Lab_QuizzInfo7.Text = Lb_QuizzInfo.Text
                    Lab_QuizzInfo70.Text = Lb_QuizzInfo1.Text
                End If
                If Index1 = 7 Then
                    Tb_Question8.Text = Lb_QuizzQuestion.Text
                    Tb_P81.Text = Lb_QuizzProposition1.Text
                    Tb_P82.Text = Lb_QuizzProposition2.Text
                    Tb_P83.Text = Lb_QuizzProposition3.Text
                    Tb_P84.Text = Lb_QuizzProposition4.Text
                    Tb_Rep8.Text = Lb_QuizzReponse.Text
                    Lab_QuizzInfo8.Text = Lb_QuizzInfo.Text
                    Lab_QuizzInfo80.Text = Lb_QuizzInfo1.Text
                End If
                If Index1 = 8 Then
                    Tb_Question9.Text = Lb_QuizzQuestion.Text
                    Tb_P91.Text = Lb_QuizzProposition1.Text
                    Tb_P92.Text = Lb_QuizzProposition2.Text
                    Tb_P93.Text = Lb_QuizzProposition3.Text
                    Tb_P94.Text = Lb_QuizzProposition4.Text
                    Tb_Rep9.Text = Lb_QuizzReponse.Text
                    Lab_QuizzInfo9.Text = Lb_QuizzInfo.Text
                    Lab_QuizzInfo90.Text = Lb_QuizzInfo1.Text
                End If
                If Index1 = 9 Then
                    Tb_Question10.Text = Lb_QuizzQuestion.Text
                    Tb_P101.Text = Lb_QuizzProposition1.Text
                    Tb_P102.Text = Lb_QuizzProposition2.Text
                    Tb_P103.Text = Lb_QuizzProposition3.Text
                    Tb_P104.Text = Lb_QuizzProposition4.Text
                    Tb_Rep10.Text = Lb_QuizzReponse.Text
                    Lab_QuizzInfo10.Text = Lb_QuizzInfo.Text
                    Lab_QuizzInfo100.Text = Lb_QuizzInfo1.Text
                End If
            Next
        End Sub

    Cela fonctionne bien avec l'index "0" de la Cb_ListQuizz car il prend bien e compte les index "0" à "9" des ListBox pour remplir le TextBosx et les Label.

    Là ou cela se gâte c'est qu'and j'appel l'index "1" de la Cb_QuizzList. En effet, il prend en compte les index "1" à "10" des Listbox alors que de par ma config je voudrais qu'il prenne les index "20 à "29" et pour l'index "2" de la Cb_QuizzListe, les index "30" à "39" et ainsi de suite.

    Je sais que mon code ne permet de faire fonctionner comme je le voudrais et c'est là que j'ai besoin de votre aide.

    Merci par avance à celui celle qui pourra me filer un coup de main pour que ca marche.

    Encore Merci
    @+ Martipit

  2. #2
    Membre chevronné
    Avatar de nouanda
    Homme Profil pro
    Hobbyist
    Inscrit en
    Mai 2002
    Messages
    246
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Australie

    Informations professionnelles :
    Activité : Hobbyist

    Informations forums :
    Inscription : Mai 2002
    Messages : 246
    Par défaut
    Là ou cela se gâte c'est qu'and j'appel l'index "1" de la Cb_QuizzList. En effet, il prend en compte les index "1" à "10" des Listbox alors que de par ma config je voudrais qu'il prenne les index "20 à "29" et pour l'index "2" de la Cb_QuizzListe, les index "30" à "39" et ainsi de suite.
    ce n;est pas plutot 10 a 19, puis 20 a 29?
    Si oui, Lb_QuizzQuestion.SelectedIndex = Cb_ListeQuizz.SelectedIndex * 10 +Index1 ?

  3. #3
    Membre confirmé
    Homme Profil pro
    Inscrit en
    Octobre 2011
    Messages
    135
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Octobre 2011
    Messages : 135
    Par défaut
    salut,

    Oui bien vu l'erreur.

    Merci je test pour voir ce que ca donne.

    @+Martipit

  4. #4
    Expert éminent Avatar de Pol63
    Homme Profil pro
    .NET / SQL SERVER
    Inscrit en
    Avril 2007
    Messages
    14 198
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : .NET / SQL SERVER

    Informations forums :
    Inscription : Avril 2007
    Messages : 14 198
    Par défaut
    pourquoi ne pas faire de la poo comme préconisé pour le langage et n'avoir que 10 lignes de code au lieu de 100 ?
    Cours complets, tutos et autres FAQ ici : C# - VB.NET

  5. #5
    Membre confirmé
    Homme Profil pro
    Inscrit en
    Octobre 2011
    Messages
    135
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Octobre 2011
    Messages : 135
    Par défaut
    Salut,

    C'est quoi la poo ????

    Merci
    @+ Martipit

  6. #6
    Expert éminent Avatar de Pol63
    Homme Profil pro
    .NET / SQL SERVER
    Inscrit en
    Avril 2007
    Messages
    14 198
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : .NET / SQL SERVER

    Informations forums :
    Inscription : Avril 2007
    Messages : 14 198
    Par défaut
    apparemment tu n'as pas accès à google chez toi ... c'est dommage parce que c'est bien pratique !

    tu aurais pu y trouver que poo = programmation orientée objet
    c'est un des précepte de .net, ce qui évite de coder en spaghetti comme en 1990 avec des if infinis et des controles nommés de partout
    oui parce qu'idéalement avant de se lancer dans un langage on est censé regarder un peu le principe de fonctionnement et ce qui est recommandé ...
    Cours complets, tutos et autres FAQ ici : C# - VB.NET

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Boucle et listbox
    Par gipn14 dans le forum Macros et VBA Excel
    Réponses: 10
    Dernier message: 07/12/2014, 19h35
  2. Boucle et Listbox
    Par kariboubou dans le forum Interfaces Graphiques
    Réponses: 4
    Dernier message: 02/10/2012, 13h20
  3. lire dans une listBox avec une boucle
    Par wolfazer dans le forum VB 6 et antérieur
    Réponses: 2
    Dernier message: 08/05/2007, 19h33
  4. Boucle avec une listbox multicolonne
    Par morgan47 dans le forum VB 6 et antérieur
    Réponses: 3
    Dernier message: 28/08/2006, 21h45

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo