Dictionnaire avec recherche dans une listbox

Description

Ce dictionnaire vous montrera tout d'abord comment rechercher dans une listbox ainsi que comment ouvrir un fichier texte à partir de la réponse trouvée.

En fait , ceci est idéal pour les débutants en vb6 qui aimerai savoir rechercher. De plus, il est très simple de le modifier pour en faire un encyclopédie avec des images.

Les chemins indiquer dans ce code ne seront pas valide, en effet, il vous faudra les changer pour que l'emplacement des fichiers texte existe. C'est le premier code que je met ici, mais ce site ma déjà apris beaucoup de chose...

Source / Exemple :


Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Any) As Long
Const LB_FINDSTRING = &H18F

Private Sub Command1_Click()
on error goto erreur
If List1.Text = vbNullString Then
MsgBox "Aucune signification trouvé", vbInformation, "Information sur la recherche"
Exit Sub
End If

If Text1.Text <> List1.Text Then
MsgBox "Terme exact non trouvé le terme le plus proche dans la liste alphabétique est " + List1.Text + ".", vbInformation, "Information sur la recherche"
End If

Open "c:\perso\dico\" + List1.Text + ".txt" For Input As #1
t1.Text = Input(LOF(1), 1)
Close #1
Exit Sub

erreur:
MsgBox "Aucune signification trouvé", vbInformation, "Information sur la recherche"

End Sub

Private Sub Command2_Click()
On Error GoTo erreur

If List1.Text = vbNullString Then
MsgBox "Aucune traduction trouvé", vbInformation, "Information sur la recherche"
Exit Sub
End If

If Text1.Text <> List1.Text Then
MsgBox "Terme exact non trouvé le terme le plus proche dans la liste alphabétique est " + List1.Text + ".", vbInformation, "Information sur la recherche"
End If

Open "c:\perso\dico\vers anglais\" + List1.Text + ".txt" For Input As #1
t1.Text = Input(LOF(1), 1)
Close #1
Exit Sub

erreur:
MsgBox "Aucune traduction trouvé", vbInformation, "Information sur la recherche"

End Sub

Private Sub Command3_Click()
On Error GoTo erreur

If List2.Text = vbNullString Then
MsgBox "Aucune traduction trouvé", vbInformation, "Information sur la recherche"
Exit Sub
End If

If Text2.Text <> List2.Text Then
MsgBox "Terme exact non trouvé le terme le plus proche dans la liste alphabétique est " + List2.Text + ".", vbInformation, "Information sur la recherche"
End If

Open "c:\perso\dico\vers français\" + List2.Text + ".txt" For Input As #1
t1.Text = Input(LOF(1), 1)
Close #1
Exit Sub

erreur:
MsgBox "Aucune traduction trouvé", vbInformation, "Information sur la recherche"

End Sub

Private Sub Form_Load()
List1.AddItem "a"
List1.AddItem "ananas"
List1.AddItem "âne"
List1.AddItem "arbre"
List1.AddItem "ane"
List1.AddItem "abattre"

List2.AddItem "aa"
List2.AddItem "Alcoholics Anonymous"
List2.AddItem "bring down"

total = List1.ListCount * 2 + List2.ListCount
Label1.Caption = "PersoDic contient " & total & " mots."

End Sub

Private Sub Option1_Click()
Command1.Visible = True
Command2.Visible = False
Command3.Visible = False

If Text2.Visible = True Then
Text1.Text = Text2.Text
End If

Text1.Visible = True
Text2.Visible = False
End Sub

Private Sub Option2_Click()
Command2.Visible = True
Command1.Visible = False
Command3.Visible = False

If Text2.Visible = True Then
Text1.Text = Text2.Text
End If

Text1.Visible = True
Text2.Visible = False
End Sub

Private Sub Option3_Click()
Command3.Visible = True
Command2.Visible = False
Command1.Visible = False

If Text1.Visible = True Then
Text2.Text = Text2.Text
End If

Text2.Visible = True
Text1.Visible = False
End Sub

Private Sub Text1_Change()
List1.ListIndex = SendMessage(List1.hwnd, LB_FINDSTRING, -1, ByVal CStr(Text1.Text))
End Sub

Private Sub Text2_Change()
List2.ListIndex = SendMessage(List2.hwnd, LB_FINDSTRING, -1, ByVal CStr(Text2.Text))
End Sub

Codes Sources

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.