Nombre d'images contenues dans userform

  • Initiateur de la discussion Initiateur de la discussion maval
  • Date de début Date de début

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

Bonjour Pierre

Je te remercie mais j'ai un souci le nombre d'image est dépendant de ma liste que j'ai en colonne "A" pour cela j'ai un code comme ceci
Code:
Private Sub UserForm_Initialize()
Dim Obj As Control, i%, Larg_Img%, Haut_Img%, Haut_Lbl%, cpt%, rang%, iMin%, iMax%, reste%
Larg_Img = 120
Haut_Img = 80
Haut_Lbl = 12
NbQ = [ListNom].Count
Arr = [ListNom].Value
cpt = 0
rang = 0

Do
iMin = 1 + 8 * rang
iMax = IIf(8 + 8 * rang <= NbQ, 8 + 8 * rang, NbQ)
For i = iMin To iMax
cpt = cpt + 1
   Set Obj = Me.Controls.Add("Forms.image.1")
   With Obj
      .Name = "img" & Format(i, "000")
      On Error Resume Next    '(en cas de photos manquantes)
      '.Picture = LoadPicture(Chemin & Arr(cpt, 1) & ".jpg") ', 250, 178)
      .Picture = LoadPicture("J:\covers small\" & Arr(cpt, 1) & ".jpg") ', 250, 178)
      On Error GoTo 0
      .PictureSizeMode = 3 '  Format 3= proportionnel
      .Tag = Format(i, "000")
     
      .BackStyle = 0 'BackStyle transparent
      .BorderStyle = 0 'BorderStyle None
     
      .Left = 12 + (Larg_Img + 12) * ((i - 1) Mod 8)
      .Top = 12 + (Haut_Img + 12) * (rang)
      .Width = Larg_Img
      .Height = Haut_Img
   End With
   ReDim Preserve Img_Trombi(1 To iMax)
   Set Img_Trombi(i).Trombi = Obj
  
   Set Obj = Me.Controls.Add("Forms.label.1")
   With Obj
      .Name = "Lbl" & Format(i, "000")
      .Tag = Format(i, "000")
      .BackStyle = 0  'BackStyle transparent
      .Caption = Arr(i, 1)
      .ForeColor = &HE0E0E0 'Police Label
      .Left = 12 + (Larg_Img + 12) * ((i - 1) Mod 8)
      .Top = 92 + (92) * (rang)
      .Width = Larg_Img
      .Height = 12
   End With
   ReDim Preserve Lbl_Trombi(1 To iMax)
   Set Lbl_Trombi(i).LblNam = Obj
  
Next i
rang = rang + 1
Loop Until cpt = NbQ

With UserForm1
k = (12 + Larg_Img) * 8 + 30
   .Width = k
   reste = IIf(Int([ListNom].Count / 10) * 10 < [ListNom].Count, 1, 0)
   .ScrollHeight = 72 * (Int([ListNom].Count / 10) + reste) + 12
   .Height = IIf(rang <= 7, 36 + (92 * rang), 516)
   .Caption = "Covers"  'Caption User
   .BackColor = &H80000012 'Couleur de fond "Noir"
End With
End Sub

et lui me trouve 1 image alors qu'il y a na 60 normale......

Je te remercie
 
Re,

Non je ne suis pas arriver même avec un compteur déclaré en Public.
Mon code User avec ton code est:
Code:
Public cpt As Integer
Private Sub UserForm_Activate()
Me.ScrollTop = 0
End Sub

Private Sub UserForm_Initialize()
Dim Obj As Control, i%, Larg_Img%, Haut_Img%, Haut_Lbl%, cpt%, rang%, iMin%, iMax%, reste%
Larg_Img = 120
Haut_Img = 80
Haut_Lbl = 12
NbQ = [ListNom].Count
Arr = [ListNom].Value
cpt = 0
rang = 0

Do
iMin = 1 + 8 * rang
iMax = IIf(8 + 8 * rang <= NbQ, 8 + 8 * rang, NbQ)
For i = iMin To iMax
cpt = cpt + 1
   Set Obj = Me.Controls.Add("Forms.image.1")
   With Obj
      .Name = "img" & Format(i, "000")
      On Error Resume Next    '(en cas de photos manquantes)
      '.Picture = LoadPicture(Chemin & Arr(cpt, 1) & ".jpg") ', 250, 178)
      .Picture = LoadPicture("J:\covers small\" & Arr(cpt, 1) & ".jpg") ', 250, 178)
      On Error GoTo 0
      .PictureSizeMode = 3 '  Format 3= proportionnel
      .Tag = Format(i, "000")
     
      .BackStyle = 0 'BackStyle transparent
      .BorderStyle = 0 'BorderStyle None
     
      .Left = 12 + (Larg_Img + 12) * ((i - 1) Mod 8)
      .Top = 12 + (Haut_Img + 12) * (rang)
      .Width = Larg_Img
      .Height = Haut_Img
   End With
   ReDim Preserve Img_Trombi(1 To iMax)
   Set Img_Trombi(i).Trombi = Obj
  
   Set Obj = Me.Controls.Add("Forms.label.1")
   With Obj
      .Name = "Lbl" & Format(i, "000")
      .Tag = Format(i, "000")
      .BackStyle = 0  'BackStyle transparent
      .Caption = Arr(i, 1)
      .ForeColor = &HE0E0E0 'Police Label
      .Left = 12 + (Larg_Img + 12) * ((i - 1) Mod 8)
      .Top = 92 + (92) * (rang)
      .Width = Larg_Img
      .Height = 12
   End With
   ReDim Preserve Lbl_Trombi(1 To iMax)
   Set Lbl_Trombi(i).LblNam = Obj
  
Next i
rang = rang + 1
Loop Until cpt = NbQ

With UserForm1
k = (12 + Larg_Img) * 8 + 30
   .Width = k
   reste = IIf(Int([ListNom].Count / 10) * 10 < [ListNom].Count, 1, 0)
   .ScrollHeight = 72 * (Int([ListNom].Count / 10) + reste) + 12
   .Height = IIf(rang <= 7, 36 + (92 * rang), 516)
   '.Height = IIf(rang <= 7, 150 + (92 * rang), 700)
   .Caption = "Covers"  'Caption User
   .BackColor = &H80000012 'Couleur de fond "Noir"
End With


For Each ctrl In UserForm1.Controls
        If TypeName(ctrl) = "Image" Then
Label1 = ("L'" & UserForm1.Name & " possede " & nb & " Images")
End If
Next
End Sub

A moins que je me suis tromper
@+
 
Bonsoir maval
Bonsoir le fil,Le Forum
Avec cette procédure tu n'arrives à rien car la variable nb n'est pas incrémentée , il me semble
VB:
For Each ctrl In UserForm1.Controls
        If TypeName(ctrl) = "Image" Then
Label1 = ("L'" & UserForm1.Name & " possede " & nb & " Images")
End If
il me semble qu'en reprenant la procédure de pierrejean et la recherche par type de tatiak
tu devrais y arrive
soit :
VB:
For Each ctrl In UserForm1.Controls
  If TypeName(ctrl) = "Image" Then
  nb = nb + 1
  End If
Next
MsgBox ("L'" & UserForm1.Name & " possede " & nb & " Images")
pas sur d'avoir tout compris LOL
Bonne fin de Soirée
Amicalement
Jean marie
 
Bonjour Max
Bonjour le Fil,Le Forum

Peut être comme ceux ci !! Lol
VB:
With Userform1
    For Each ctrl In .Controls
      If TypeName(ctrl) = "Image" Then
      nb = nb + 1
      End If
    Next
       .Caption = "L'" & .Name & " possede " & nb & " Images"
End With
Bonne fin de Journée
Amicalement
Jean Marie
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

Réponses
2
Affichages
163
Réponses
2
Affichages
162
Retour