Besoin d'aide pour un compteur de Polindrome dans une chaine de caractère

cs_Ghis Messages postés 8 Date d'inscription samedi 11 mai 2002 Statut Membre Dernière intervention 7 juin 2002 - 14 mai 2002 à 01:21
fredlynx Messages postés 662 Date d'inscription mercredi 16 janvier 2002 Statut Modérateur Dernière intervention 16 octobre 2010 - 14 mai 2002 à 08:09
Voici mon code pour l'instant. J'ai un bug et n'arrive pas a la trouver. :/

P.S: Un Palindrome, c'est un mot qui s'écrit parreil des deux côté. Ex: ALLA ou BOB

Option Explicit

Private Sub cmdRechercher_Click()

Dim intCompteur As Integer
Dim lngIndice As Long
Dim strMot As String
Dim lngDebut As Long

lngIndice = InStr(1, txtTexte.Text, " ", vbTextCompare)

If lngIndice <> 0 Then

lngDebut = 1
Do Until lngIndice = 0

lngIndice = InStr(lngDebut, txtTexte.Text, " ", vbTextCompare)
strMot = Mid(txtTexte, lngDebut, lngIndice)

If StrReverse(strMot) = strMot Then
intCompteur = intCompteur + 1
End If
lngDebut = lngIndice + 1
Loop
Else
lngIndice = InStr(1, txtTexte.Text, " ", vbTextCompare)

If lngIndice <> 0 Then
If StrReverse(strMot) = strMot Then
intCompteur = intCompteur + 1
End If
End If
End If

MsgBox intCompteur
End Sub

1 réponse

fredlynx Messages postés 662 Date d'inscription mercredi 16 janvier 2002 Statut Modérateur Dernière intervention 16 octobre 2010 3
14 mai 2002 à 08:09
ca ça devrait marcher ... enfin si ta fonction reverse fonctionne ... A toi d'analyser ;)

Option Explicit

Private Sub cmdRechercher_Click()
Dim intCompteur As Integer
Dim lngIndice As Long
Dim strMot As String
Dim lngDebut As Long
Dim StrTemp As String

StrTemp = Trim(txtTexte.Text)
If InStr(StrTemp, " ") <> 0 Then
lngDebut = 1
Do
lngIndice = InStr(lngDebut, StrTemp, " ")
If lngIndice = 0 Then Exit Do
strMot = Trim(Mid(txtTexte, lngDebut, lngIndice - 1))
If StrReverse(strMot) = strMot Then
intCompteur = intCompteur + 1
End If
lngDebut = lngIndice + 1
Loop
Else
If Len(StrTemp) > 0 Then
If StrReverse(StrTemp) = StrTemp Then
intCompteur = intCompteur + 1
End If
End If
End If
MsgBox intCompteur
End Sub

<center>http://www.lynx-asp.fr.st
WebMaster </center>
0
Rejoignez-nous