Rogan Thoerson
Messages postés12Date d'inscriptionjeudi 31 août 2006StatutMembreDernière intervention 5 septembre 2006
-
5 sept. 2006 à 11:51
Rogan Thoerson
Messages postés12Date d'inscriptionjeudi 31 août 2006StatutMembreDernière intervention 5 septembre 2006
-
5 sept. 2006 à 12:05
Salut
J'aimerai savoir ce qui ne va pas dans mon code. C'est très certainement une erreur toute bete mais j'arrive pas a la trouvée. J'ai vu aussi que quand le code est terminé la variable shortstring est vide je ne comprends pas pourquoi. Normallement tout est dans le code pour pouvoir le comprendre.
Merci
Voici le code
Public Function Nombre02(ByVal Chaineconvert02 As String) As String
'Sortir des nombre d'un texte en string de la forme "blablablabla124547blablabla" et même"bla1bla2bal3"'
Dim Taillestr As Integer
Dim Shortstring As String
Dim Comptstr As Integer
Shorstring = ""
Comptstr = 1
Taillestr = Len(Chaineconvert)
While Comptstr <= Taillestr If Mid(Chaineconvert, Comptstr, 1) "0" Or Mid(Chaineconvert, Comptstr, 1) "1" Or Mid(Chaineconvert, Comptstr, 1) = "2" Or Mid(Chaineconvert, Comptstr, 1) = "3" Or Mid(Chaineconvert, Comptstr, 1) = "4" Or Mid(Chaineconvert, Comptstr, 1) = "5" Or Mid(Chaineconvert, Comptstr, 1) = "6" Or Mid(Chaineconvert, Comptstr, 1) = "7" Or Mid(Chaineconvert, Comptstr, 1) = "8" Or Mid(Chaineconvert, Comptstr, 1) = "9" Then
Shortstring = Shortstring & Mid(Chaineconvert, Comptstr, 1)
End If
Comptstr = Comptstr + 1
Wend
Nombre02 = CInt(Shortstring)
End Function
jrivet
Messages postés7392Date d'inscriptionmercredi 23 avril 2003StatutMembreDernière intervention 6 avril 201260 5 sept. 2006 à 11:56
Salut,
Un petit conseil place
Option Explicit
en haut de ton code cela aurait pu eviter cette question
Tu utilisais une variable appelé Chaineconvert
elle n'existe oas dans cette fonction
Public Function Nombre02(ByVal Chaineconvert02 As String) As String
'Sortir des nombre d'un texte en string de la forme "blablablabla124547blablabla" et même"bla1bla2bal3"'
Dim Taillestr As Integer
Dim Shortstring As String
Dim Comptstr As Integer
'Avant Shorstring = ""
Shortstring = ""
Comptstr = 1
'Avant Taillestr = Len(Chaineconvert)
Taillestr = Len (Chaineconvert02)
While Comptstr < = Taillestr If Mid(Chaineconvert02, Comptstr, 1) "0" Or Mid (Chaineconvert02, Comptstr, 1) "1" Or Mid(Chaineconvert02, Comptstr, 1) = "2" Or Mid (Chaineconvert02, Comptstr, 1) = "3" Or Mid(Chaineconvert02, Comptstr, 1) = "4" Or Mid (Chaineconvert02, Comptstr, 1) = "5" Or Mid(Chaineconvert02, Comptstr, 1) = "6" Or Mid (Chaineconvert02, Comptstr, 1) = "7" Or Mid(Chaineconvert02, Comptstr, 1) = "8" Or Mid (Chaineconvert02, Comptstr, 1) = "9" Then
Shortstring = Shortstring & Mid (Chaineconvert02, Comptstr, 1)
End If
Comptstr = Comptstr + 1
Wend
'Inutile le Cint c'est une chaine de caractere qui doit etre retourne
Nombre02 = Shortstring
End Function
jrivet
Messages postés7392Date d'inscriptionmercredi 23 avril 2003StatutMembreDernière intervention 6 avril 201260 5 sept. 2006 à 11:59
Re,
Note si tu veux a chaque en resortir juste les chiffres, je te propose la fonction IsNumeric qui t'évite tout les tests.
Public Function Nombre02(ByVal Chaineconvert02 As String) As String
'Sortir des nombre d'un texte en string de la forme "blablablabla124547blablabla" et même"bla1bla2bal3"'
Dim Shortstring As String
Dim Comptstr As Integer
For Comptstr = 1 To Len (Chaineconvert02)
If IsNumeric(Mid(Chaineconvert02, Comptstr, 1)) Then Shortstring = Shortstring & Mid(Chaineconvert02, Comptstr, 1)
Next
Nombre02 = Shortstring
End Function