OVH Cloud OVH Cloud

bouton de recherche

2 réponses
Avatar
ticul
j'ai fais un bouton de recherche en vb6 et losrque je=20
l'essai pour voir si il fonctionne il ne m'affiche pas=20
ma recherche. vers un fichier s=E9quentiel.

voici le code=20

Private Sub cmdRechercher_Click()
Const conmess As String =3D "Entrez le nom et Pr=E9nom:"
Const contitre As String =3D "Carnet"
Const conMsg As String =3D "Recherche infructueuse."
strrecherche =3D InputBox(conmess, contitre)
intPosTrouve =3D InStr(1, strNom =3D txtNom.Text,=20
strprenom =3D txtPrenom.Text, 1)
If intPosTrouve =3D 0 Then
intValRenvoi =3D MsgBox(conMsg,=20
conBtns, "rechercher")
End If

End Sub




.

2 réponses

Avatar
François Picalausa
Bonjour/soir,

intPosTrouve = InStr(1, strNom = txtNom.Text,
strprenom = txtPrenom.Text, 1)



Tu demande à VB de rechercher dans True ou False (en focntion du fait que
strNom = txtNom.Text soit vrai ou faux) dans un autre vrai/faux.

Essaye ceci:

Dim strNom As String
Dim strPrenom As String
strNom = txtNom.Text
strprenom = txtPrenom.Text
intPosTrouve = InStr(1, strNom, strPrenom, 1)

Là, on demander de retrouver strPrenom dans strNom

If intPosTrouve = 0 Then
intValRenvoi = MsgBox(conMsg,
conBtns, "rechercher")
End If



Il ne t'affichera jamais que ta recherche a réussi si tu n'ajoute pas une
clause else dans le if

--
François Picalausa (MVP VB)
FAQ VB : http://faq.vb.free.fr
MSDN : http://msdn.microsoft.com


"ticul" a écrit dans le message
de news:671301c3e669$3aad0d00$
j'ai fais un bouton de recherche en vb6 et losrque je
l'essai pour voir si il fonctionne il ne m'affiche pas
ma recherche. vers un fichier séquentiel.

voici le code

Private Sub cmdRechercher_Click()
Const conmess As String = "Entrez le nom et Prénom:"
Const contitre As String = "Carnet"
Const conMsg As String = "Recherche infructueuse."
strrecherche = InputBox(conmess, contitre)
intPosTrouve = InStr(1, strNom = txtNom.Text,
strprenom = txtPrenom.Text, 1)
If intPosTrouve = 0 Then
intValRenvoi = MsgBox(conMsg,
conBtns, "rechercher")
End If

End Sub


Avatar
Pascal B.
Salut (beau) ticul,

La fonction ne fonctionne pas comme çà !
Voici la syntaxe exacte:

InStr([start, ]string1, string2[, compare])

String2 est le texte à rechercher dans String1

Donc, il faut écrire:

intPosTrouveNom = InStr(1, txtNom.Text, strNom,1)
intPosTrouvePrenom = InStr(1, txtPrenom.Text, strPrenom,1)
If intPosTrouveNom = 0 And intPosTrouvePrenom = 0 then
intValRenvoi = MsgBox(conMsg, conBtns, "rechercher")
End If

"ticul" a écrit dans le message de
news:671301c3e669$3aad0d00$
j'ai fais un bouton de recherche en vb6 et losrque je
l'essai pour voir si il fonctionne il ne m'affiche pas
ma recherche. vers un fichier séquentiel.

voici le code

Private Sub cmdRechercher_Click()
Const conmess As String = "Entrez le nom et Prénom:"
Const contitre As String = "Carnet"
Const conMsg As String = "Recherche infructueuse."
strrecherche = InputBox(conmess, contitre)
intPosTrouve = InStr(1, strNom = txtNom.Text,
strprenom = txtPrenom.Text, 1)
If intPosTrouve = 0 Then
intValRenvoi = MsgBox(conMsg,
conBtns, "rechercher")
End If

End Sub




.