patricktoulon
XLDnaute Barbatruc
bonsoir a tous
j'ai un petit soucis avec evaluate
il me donne une erreur codé en dynamique et me donne le resultat ecrit en dur
des idées???
j'ai un petit soucis avec evaluate
il me donne une erreur codé en dynamique et me donne le resultat ecrit en dur
VB:
Option Explicit
Sub test()
Dim x$
x = "cent mille"
MsgBox NbLettreToNumeric(x)
x = "un million"
MsgBox NbLettreToNumeric(x)
x = "neuf cent soixante six milliards cinq cent soixante-neuf millions six cent cinquante-cinq mille quatre cent dix-huit Euros "
MsgBox NbLettreToNumeric(x)
End Sub
Function NbLettreToNumeric(x As String)
Dim Lettres, Chiffre, unitM, Multipl, i&, Segments, m&, s$, ch, c&, ind&, z#, texte$, tb
Lettres = Array("", "un", "deux", "trois", "quatre", "cinq", "six", "sept", _
"huit", "neuf", "dix", "onze", "douze", "treize", "quatorze", "quinze", "seize", "dix-sept", "dix-huit", "dix-neuf", _
"vingt", "trente", "quarante", "cinquante", "soixante", "soixante dix", "quatre vingt", "quatre vingt dix", "cent", _
"mille", "million", "milliard", "mille", "millions", "milliards")
Chiffre = Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 30, 40, 50, 60, 70, 80, 90, "*100", "*1000|", "*1000000|", "*1000000000|", "*1000|", "*1000000|", "*1000000000|")
x = Replace(Replace(x, " et ", " "), "d'", " ")
x = Replace(Replace(x, "Euros", ""), "Euro", "")
x = Replace(x, "-", " ")
ch = Split(Application.Trim(x), " ")
For c = LBound(ch) To UBound(ch)
ind = WorksheetFunction.Match(ch(c), Lettres, 0) - 1
s = Trim(s) & " " & Chiffre(ind) & "+"
s = Replace(s, "+ *", "*")
s = IIf(Left(s, 1) = "*", 1 & s, s)
Next c
s = s & "0"
tb = Split(s, "|")
For i = 0 To UBound(tb)
texte = texte & "(" & Replace(tb(i), "*1000", ")*1000") & "+"
texte = Replace(Replace(texte, "+ )", ")"), "(+", "(")
Next
'NbLettreToNumeric = Evaluate(texte)
Debug.Print Replace(texte, " ", "") & "0)"
Debug.Print Evaluate(Replace(texte, " ", ""))
Debug.Print "---------------------------------------------"
End Function
'pour tant ici ca match '
Sub test2()
MsgBox Evaluate("(9*100+ 60+ 6)*1000000000+( 5*100+ 60+ 9)*1000000+( 6*100+ 50+ 5)*1000+( 4*100+ 10+ 8+0+0)")
End Sub