XL 2016 autre façon pour écrire un code

lynyrd

XLDnaute Impliqué
Bonjour le forum
y a t'il une autre façon d'ècrire ce code.
Merci.
 

Pièces jointes

  • VIDEOTHEQUE_COSTA.zip
    852.3 KB · Affichages: 19
C

Compte Supprimé 979

Guest
Re,

300 ne passe pas car tu n'as pas de "300.gif"

Pour tes drapeaux il y a beaucoup plus simple, dans ta BdD il faut enregistrer le pays (France, USA, etc...)
Ensuite tu n'as qu'à mettre tes fichiers : France.gif, USA.gif, etc...

A+
 

_Thierry

XLDnaute Barbatruc
Repose en paix
Bonjour @lynyrd & l'OM !, @BrunoM45 , le Forum

Je suis d'accord avec toi Bruno, pour les Pays, il y a bien plus simple ...


video.gif


Pour la gestion des images inexistantes voici le code que j'utiliserais à la place du tien Lynyrd :

VB:
Private Sub listbox1_Click()
Dim Chemin As String
Dim Chemin1 As String
Dim Photo As String


  nl = Me.ListBox1.Column(2, Me.ListBox1.ListIndex)
  For x = 0 To 12
    Me.Controls("TextBox" & x + 1).Value = Sheets("Feuil1").Cells(nl, 1 + x)
    Me.TextBox15.Value = Sheets("Feuil1").Cells(nl, 15)
   
    Next x
    With Me.TextBox1
      .SelStart = 0
    .SelLength = Len(.Value)
End With


' ****************************************************
' Indiques exactement le répertoire de tes images
' ****************************************************
Chemin = ThisWorkbook.Path & "/affiches/"
Chemin1 = ThisWorkbook.Path & "/drapeaux/"


Photo = Dir(Chemin & Me.ListBox1.Text & ".jpg")
    If Photo <> "" Then
        With Me.Image1
        .Picture = LoadPicture(Chemin & Me.ListBox1.Text & ".jpg") 'Si la photo existe
        End With
    Else
        With Me.Image1
        .Picture = LoadPicture(Chemin & "NotFound.jpg")            'Si elle n'existe pas ! on met L'image prévue à cette fin !
        End With

    End If

If Me.TextBox15 <> "" Then
    Photo = Dir(Chemin1 & Me.TextBox15.Text & ".gif")
    If Photo <> "" Then
        With Me.Image2
        .Picture = LoadPicture(Chemin1 & Me.TextBox15.Text & ".gif") 'Si la photo existe
        End With
    Else
        With Me.Image2
        .Picture = LoadPicture(Chemin1 & "NotFound.gif")            'Si elle n'existe pas ! on met L'image prévue à cette fin !
        End With

    End If

Else
    Me.Image2.Picture = LoadPicture(Chemin1 & "NotFound.gif")
End If

End Sub

Pour ta base je rajoute une colonne :
Capture.JPG


Et pour les drapeaux je n'ai plus besoin que des Pays :

Capture.JPG


Et pour les Affiches j'ai ajouté le
Capture.JPG


Voilà pour le reste je n'ai pas trop regardé

Bien à toi, à vous
@+Thierry
 
Dernière édition:

fanch55

XLDnaute Barbatruc
Salut,
Pourquoi le film 300 ne passe pas.
Quel code faut t'il mettre pour le lecteur windows media ?
Merci.
Correction bestiale qui n'empêche pas l’exécution :

Private Sub listbox1_Click()
Dim Chemin As String
Dim Chemin1 As String
Dim Chemin2 As String
Dim Chemin3 As String
Dim Chemin4 As String

' ****************************************************
' Indiques exactement le répertoire de tes images
' ****************************************************
Chemin = ThisWorkbook.Path & "\affiches\"
Chemin1 = ThisWorkbook.Path & "\drapeaux\"
Chemin2 = ThisWorkbook.Path & "\acteurs\"
Chemin3 = ThisWorkbook.Path & "\acteurs1\"
Chemin4 = ThisWorkbook.Path & "\acteurs2\"


For x = 0 To 5
Next x
On Error Resume Next
Me.Image1.Picture = LoadPicture(Chemin & Me.ListBox1 & ".jpg")
Me.Image2.Picture = LoadPicture(Chemin1 & Me.ListBox1 & ".gif")
Me.Image3.Picture = LoadPicture(Chemin2 & Me.ListBox1 & ".jfif")
Me.Image4.Picture = LoadPicture(Chemin3 & Me.ListBox1 & ".jfif")
Me.Image5.Picture = LoadPicture(Chemin4 & Me.ListBox1 & ".jfif")
On Error GoTo 0

nl = Me.ListBox1.Column(2, Me.ListBox1.ListIndex)
For x = 0 To 12
Me.Controls("TextBox" & x + 1).Value = Sheets("Feuil1").Cells(nl, 1 + x)
Next x
With Me.TextBox1
.SelStart = 0
.SelLength = Len(.Value)
End With

With Me.WindowsMediaPlayer1
.Url = "Nom Du film et son chemin dans la table"
CommandButton3.Visible = True
CommandButton3_Click
End With

End Sub
Pour Windows média : création d'un bouton supplémentaire
1587930193675.png

VB:
Private Sub CommandButton3_Click()
Dim Fin As Date
    With Me.WindowsMediaPlayer1
        Fin = Time + TimeValue("00:00:05") ' 5 secondes pour être accessible
        Do While .playState = wmppsTransitioning And Time < Fin
            DoEvents
        Loop
        Select Case True
            Case .playState = wmppsReady
                Me.CommandButton3.Caption = "Play"
            Case .Controls.isAvailable("Pause"):
                .Controls.pause
                Me.CommandButton3.Caption = "Play"
            Case .Controls.isAvailable("Play"):
                .Controls.Play
                Me.CommandButton3.Caption = "Pause"
    End Select
End With
End Sub

C'est pour dépanner et te faire avancer, sinon, il faut absolument faire ce qu'a dit @_Thierry pour initialiser tout ça.
Tu pourrais également mettre des options par défaut dans ton Userform, car ce n'est pas très intuitif à prime abord ... ;)
 

Discussions similaires

Réponses
24
Affichages
411
Réponses
2
Affichages
205

Statistiques des forums

Discussions
312 178
Messages
2 085 980
Membres
103 079
dernier inscrit
sle