cs_Fabian123
Messages postés180Date d'inscriptionvendredi 18 janvier 2008StatutMembreDernière intervention22 novembre 2013
-
25 mars 2008 à 14:34
cs_Fabian123
Messages postés180Date d'inscriptionvendredi 18 janvier 2008StatutMembreDernière intervention22 novembre 2013
-
25 mars 2008 à 15:32
bonjour!
voilà, j'ai deux evenements click identiques, mais liés à deux listbox, est-il possible d'encoder l'evenement dans une sub et de l'appeler dans les evenement de ma listbox?
voilà mes codes, j'ai essayé de ne faire qu'une seule sub et de l'appeler dans mes listbox, mais ça plante...
Private Sub ListeStock_Click()
Dim i As Integer
i = ListeStock.ListIndex
If Dir$("d:\profiles\beufab\Bureau\Images" & .List(.ListIndex, 0) & ".jpg") = "" Then
Set ImageArticle.Picture = LoadPicture("d:\Images\default.jpg")
Else
Set ImageArticle.Picture = LoadPicture("d:\Images" & .List(.ListIndex, 0) & ".jpg")
End If
InfoArticle.Caption = ListeStock.List(i, 0)
InfoPrix.Caption = ListeStock.List(i, 1)
End Sub
Private Sub ListeVente_Click()
Dim i As Integer
i = ListeVente.ListIndex
With ListeVente
If Dir$("d:\\Images" & .List(.ListIndex, 0) & ".jpg") = "" Then
Set ImageArticle.Picture = LoadPicture("d:\Images\default.jpg")
Else
Set ImageArticle.Picture = LoadPicture("d:\Images" & .List(.ListIndex, 0) & ".jpg")
End If
InfoArticle.Caption = ListeVente.List(i, 0)
InfoPrix.Caption = ListeVente.List(i, 1)
End With
End Sub
j'ai essayé ceci, mais ça plante au niveau de la ligne .list(.listindex)...
Private Sub AfficherImage()
Dim i As Integer
If Dir$("d:\profiles\beufab\Bureau\Images" & .List(. ListIndex , 0) & ".jpg") = "" Then
Set ImageArticle.Picture = LoadPicture("d:\Images\default.jpg")
Else
Set ImageArticle.Picture = LoadPicture("d:\Images" & .List(.ListIndex, 0) & ".jpg")
End If
InfoArticle.Caption = ListeStock.List(i, 0)
InfoPrix.Caption = ListeStock.List(i, 1)
End Sub
Private Sub ListeStock_Click()
i = ListeStock.ListIndex
With liststock
Call AfficherImage
End With
End Sub
Private Sub ListeVente_Click()
i = ListeVente.ListIndex
With liststock
Call AfficherImage
End With
End Sub
Le grand Zorro
Messages postés50Date d'inscriptionmercredi 4 août 2004StatutMembreDernière intervention12 mai 2008 25 mars 2008 à 14:39
Bonjour,
Pourquoi ne pas créer une procédure que tu appelle dans chacun des événement click et passer en paramètre la référence de la listebox et celle de l'image.
genre:
sub AfficherImageDansListBox(by ref LeControl as ListBox, byval LImage as string) Ou quelque chose du genre..
jrivet
Messages postés7392Date d'inscriptionmercredi 23 avril 2003StatutMembreDernière intervention 6 avril 201260 25 mars 2008 à 14:40
Salut,
Tu dois passer ne parametre à afficherImage le list box.
Regarde un exemple
Private Sub ListeStock_Click()
Call ProcessListClick(ListeStock)
End Sub<hr />
Private Sub ListeVente_Click()
Call ProcessListClick(ListeVente)
End Sub<hr />
Private Sub ProcessListClick(L As ListBox)
Dim i As Integer
i = L.ListIndex
With L
If Dir$("d:\\Images\" & .List(i, 0) & ".jpg") = vbNullString Then
Set ImageArticle.Picture = LoadPicture("d:\Images\default.jpg")
Else
Set ImageArticle.Picture = LoadPicture("d:\Images\" & .List(i, 0) & ".jpg")
End If
InfoArticle.Caption = .List(i, 0)
InfoPrix.Caption = .List(i, 1)
End With
End Sub<hr />
, ----
[code.aspx?ID=41455 By Renfield]
jrivet
Messages postés7392Date d'inscriptionmercredi 23 avril 2003StatutMembreDernière intervention 6 avril 201260 25 mars 2008 à 14:41
Re,
Voila...le temps que je prépare... et [auteur/LEGRANDZORRO/318197.aspx Le grand Zorro] t'as soufflé la même chose.
NOTE:
C'est mieux
Private Sub ProcessListClick(L As ListBox)
Dim i As Integer
With L
i = .ListIndex If Dir$( "d:\\Images" & .List(i, 0) & ".jpg") = vbNullString Then
Set ImageArticle.Picture = LoadPicture( "d:\Images\default.jpg" )
Else
Set ImageArticle.Picture = LoadPicture("d:\Images" & .List(i, 0) & ".jpg")
End If
InfoArticle.Caption = .List(i, 0 )
InfoPrix.Caption = .List(i, 1)
End With
End Sub
jrivet
Messages postés7392Date d'inscriptionmercredi 23 avril 2003StatutMembreDernière intervention 6 avril 201260 25 mars 2008 à 15:24
Re,
J'avais pas vu la catégorie.
Essaie peu être
Private Sub ProcessListClick(L As MSForms.ListBox)
Dim i As Integer
With L
i = .ListIndex
If Dir$("d:\\Images\" & .List(i, 0) & ".jpg") = vbNullString Then
Set ImageArticle.Picture = LoadPicture("d:\Images\default.jpg")
Else
Set ImageArticle.Picture = LoadPicture("d:\Images\" & .List(i, 0) & ".jpg")
End If
InfoArticle.Caption = .List(i, 0)
InfoPrix.Caption = .List(i, 1)
End With
End Sub<hr />
, ----
[code.aspx?ID=41455 By Renfield]
Si cela ne fonctionne toujours pas, il va falloir que tu nous rappelle où sont placées tes ListBox