Sortir des chiffre d'une chaine de caractère

Résolu
Rogan Thoerson Messages postés 12 Date d'inscription jeudi 31 août 2006 Statut Membre Dernière intervention 5 septembre 2006 - 5 sept. 2006 à 11:51
Rogan Thoerson Messages postés 12 Date d'inscription jeudi 31 août 2006 Statut Membre Derniè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

5 réponses

jrivet Messages postés 7392 Date d'inscription mercredi 23 avril 2003 Statut Membre Dernière intervention 6 avril 2012 60
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 
 

<small> Coloration syntaxique automatique [AFCK]</small>
       

@+,   Ju£i?n
3
jrivet Messages postés 7392 Date d'inscription mercredi 23 avril 2003 Statut Membre Dernière intervention 6 avril 2012 60
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 
 







<small> Coloration syntaxique automatique [AFCK]</small>

       









 






@+,   Ju£i?n
3
Rogan Thoerson Messages postés 12 Date d'inscription jeudi 31 août 2006 Statut Membre Dernière intervention 5 septembre 2006
5 sept. 2006 à 12:00
bien vu merci
0
Rogan Thoerson Messages postés 12 Date d'inscription jeudi 31 août 2006 Statut Membre Dernière intervention 5 septembre 2006
5 sept. 2006 à 12:01
heu Isnumeric ca marche en Vbasic6 ?
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
Rogan Thoerson Messages postés 12 Date d'inscription jeudi 31 août 2006 Statut Membre Dernière intervention 5 septembre 2006
5 sept. 2006 à 12:05
Franchement merci ca marche du tonnerre de dieu maintenant
0
Rejoignez-nous