Alexx56
Messages postés7Date d'inscriptionjeudi 8 décembre 2005StatutMembreDernière intervention10 décembre 2005
-
8 déc. 2005 à 13:36
Alexx56
Messages postés7Date d'inscriptionjeudi 8 décembre 2005StatutMembreDernière intervention10 décembre 2005
-
8 déc. 2005 à 22:34
Bonjour,
j'ai besoin de votre aide pour réaliser un projet vb.
L'objectif est de faire apparaitre une MsgBox ou une image (lien vers un autre fichier) après avoir sélectionné un OptionButton puis la donnée recherchée dans une ListBox.
Ex: Sélectionner une couleur parmi 4 OptionButton puis la forme d'une figure dans une ListBox et à partir de là faire apparaitre le message ou l'image.
existe-t-ils des codes pouvant effectuer ce genre d'opératon?
Merci pour vos éventuelles réponses
violent_ken
Messages postés1812Date d'inscriptionmardi 31 mai 2005StatutMembreDernière intervention26 octobre 20102 8 déc. 2005 à 21:47
Violent Ken
salut !
Je suis pas sur d'avoir vraiment compris le problème, mais essaie cet exemple :
tu copies tout çà dans un fichier texte et tu enregistres en *.frm
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3180
ClientLeft = 60
ClientTop = 375
ClientWidth = 4605
LinkTopic = "Form1"
ScaleHeight = 3180
ScaleWidth = 4605
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton Command2
Caption = "ImageBox"
Height = 375
Left = 240
TabIndex = 6
Top = 1920
Width = 1815
End
Begin VB.CommandButton Command1
Caption = "MsgBox"
Height = 375
Left = 240
TabIndex = 5
Top = 1560
Width = 1815
End
Begin VB.OptionButton Option1
Caption = "Bleu"
Height = 255
Index = 3
Left = 120
TabIndex = 4
Top = 1080
Width = 1815
End
Begin VB.ListBox List1
Height = 1425
Left = 2280
TabIndex = 3
Top = 240
Width = 1335
End
Begin VB.OptionButton Option1
Caption = "Rouge"
Height = 255
Index = 2
Left = 120
TabIndex = 2
Top = 840
Width = 1815
End
Begin VB.OptionButton Option1
Caption = "Jaune"
Height = 255
Index = 1
Left = 120
TabIndex = 1
Top = 600
Width = 1815
End
Begin VB.OptionButton Option1
Caption = "Vert"
Height = 255
Index = 0
Left = 120
TabIndex = 0
Top = 360
Width = 1815
End
Begin VB.Image Image1
Height = 1215
Left = 2280
Stretch = -1 'True
Top = 1800
Width = 2175
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
'alors on affiche une msgbox
Dim X As Long, Y As Long
For X = 1 To List1.ListCount
For Y = 1 To Option1.Count
If Option1(Y - 1) And List1.ListIndex = X - 1 Then
Dim ChoixOption As Long, ChoixListe As Long ChoixOption Y: ChoixListe X
'alors en fonction de choixoption (numéro de l'index du optionbutton coché)
'et en fonction de choixliste (index de l'élément sélectionné dans la liste)
'tu affiches la msgbox que tu veux
'exemple
Dim Couleur As String, Forme As String If ChoixOption 1 Then Couleur "vert" If ChoixOption 2 Then Couleur "jaune" If ChoixOption 3 Then Couleur "rouge" If ChoixOption 4 Then Couleur "bleu" If ChoixListe 1 Then Forme "carré" If ChoixListe 2 Then Forme "rectangle" If ChoixListe 3 Then Forme "rond" If ChoixListe 4 Then Forme "parallépipédique" If ChoixListe 5 Then Forme "triangulaire"
'...etc
End If
Next Y
Next X
'affichage de la msgbox
MsgBox "Vous avez choisit la couleur : " & Couleur & vbNewLine & "Vous avez choisit la forme : " & Forme, vbInformation, "Résultats"
End Sub
Private Sub Command2_Click()
'alors on affiche une image
Dim Path As String
Path = "C:\Ressources_images" 'dossier contenant des images
Dim X As Long, Y As Long
For X = 1 To List1.ListCount
For Y = 1 To Option1.Count
If Option1(Y - 1) And List1.ListIndex = X - 1 Then
Dim ChoixOption As Long, ChoixListe As Long ChoixOption Y: ChoixListe X
'alors en fonction de choixoption (numéro de l'index du optionbutton coché)
'et en fonction de choixliste (index de l'élément sélectionné dans la liste)
'tu affiches l'image que tu veux que tu veux
'exemple
Dim Couleur As String, Forme As String If ChoixOption 1 Then Couleur "vert" If ChoixOption 2 Then Couleur "jaune" If ChoixOption 3 Then Couleur "rouge" If ChoixOption 4 Then Couleur "bleu" If ChoixListe 1 Then Forme "carré" If ChoixListe 2 Then Forme "rectangle" If ChoixListe 3 Then Forme "rond" If ChoixListe 4 Then Forme "parallépipédique" If ChoixListe 5 Then Forme "triangulaire"
'...etc
End If
Next Y
Next X
'affichage de l'image
Path = Path & "" & Couleur & "" & Forme & ".jpg"
'path renvoie par exemple "c:\ressources_images\jaune\carré.jpg" donc faudra placer tes dossiers et images en fonction
Image1.Picture = LoadPicture(Path)
End Sub
Private Sub Form_Load()
'initialisation de la liste
List1.AddItem "carré"
List1.AddItem "rectangle"
List1.AddItem "rond"
List1.AddItem "parallèpipédique"
List1.AddItem "triangulaire"
End Sub
'__________________________________________