Projet VBA

Fermé
Gaet - 7 juin 2013 à 10:14
Gaet33 Messages postés 1 Date d'inscription vendredi 7 juin 2013 Statut Membre Dernière intervention 7 juin 2013 - 7 juin 2013 à 10:29
Bonjour à tous !
J'espère que je serais clair ^^
J'aimerai faire un projet en VBA Excel qui consiste à faire une application pour un professeur où il pourrait saisir ou modifer des classes ou des élèves, les supprimer, saisir leurs moyennes etc.. Je coince sur 2 fonctions qui ne marchent pas : sélectionner une classe ou un élève

Voici les déclarations :
Option Explicit

Const Max = 100

Type Eleve
    Nom As String
    Prenom As String
    DateN As Date
    Classe As String
    eMail As String
    S1 As Single
    S2 As Single
End Type

Public TablE(0 To Max) As Eleve
Public NbE As Integer
Public TablC(1 To 10) As String
Public NbC As Integer
Public indice As Integer


J'ai un jeu de test de 20 élèves et 2 classes (10 dans chaque) du style :
TablE(1).Nom = "Aupay"
TablE(1).Prenom = "Alice"
TablE(1).Classe = "STID1"
TablE(1).DateN = "24/03/1994"
TablE(1).S1 = -1
TablE(1).S2 = -1

Je bloque sur ces deux fonctions :
Function selectionClasse(ByVal titre As String) As Integer
Dim i As Integer
Dim tab_I(1 To Max) As Integer
Dim cpt As Integer
Dim res As Integer
Dim txt As String
Dim Chx As Variant

res = 0
cpt = 0
txt = "Selectionner la classe " & titre & vbcr
For i = 1 To NbC
    
    cpt = cpt + 1
    txt = txt & cpt & " : " & TablC(i) & vbcr
    tab_I(cpt) = i
    
Next i
txt = txt & 0 & " : " & "Annuler" 'derniere ligne
If cpt > 0 Then
    Chx = InputBox(txt, "Selection", 0)
    Do While (Chx < 0 Or Chx > cpt) And Chx <> ""
        Chx = InputBox(txt, "Selection", 0)
    Loop
    If Chx <> 0 And Chx <> "" Then
        res = tab_I(Chx)
    End If
End If

selectionClasse = res
End Function


ET :

Function selectionEleve(ByVal c As String, ByVal titre As String) As Integer
Dim i As Integer
Dim tab_I(1 To Max) As Integer
Dim cpt As Integer
Dim res As Integer
Dim txt As String
Dim Chx As Variant

res = 0
cpt = 0
txt = "Selectionner l'élève " & titre & vbcr
For i = 1 To NbE
    If TablE(i).Nom = c Then
        cpt = cpt + 1
        txt = txt & cpt & " : " & TablE(i).Nom & " " & TablE(i).Prenom & vbcr
        tab_I(cpt) = i
    End If
Next i
txt = txt & 0 & " : " & "Annuler" 'derniere ligne
If cpt > 0 Then
    Chx = InputBox(txt, "Selection", 0)
    Do While (Chx < 0 Or Chx > cpt) And Chx <> ""
        Chx = InputBox(txt, "Selection", 0)
    Loop
    If Chx <> 0 And Chx <> "" Then
        res = tab_I(Chx)
    End If
End If

selectionEleve = res
End Function


Je sais pour SelectionEleve qu'il faut d'abord prendre en compte la classe avant l'élève mais je sais pas comment faire. Voilà j'espère que vous serez m'aidez ^^ ! Je vous remercie d'avance

1 réponse

Gaet33 Messages postés 1 Date d'inscription vendredi 7 juin 2013 Statut Membre Dernière intervention 7 juin 2013
Modifié par Gaet33 le 7/06/2013 à 10:29
C'est moi qui ai posté le message, je l'ai bêtement écrit avant de m'identifier ^^.
0