module de classe et fonction récursive.
Source / Exemple :
Option Explicit
'--------------
'CF >>
'http://perso.club-internet.fr/petrequin/mathema/traites/orthnombres/ro_nombres.html
'-----------------------------------------------------------------------------------
'il reste à mettre les traits d'unions aux bons endroits !!!
'et surment quelques erreurs...
'@+, VIC
'------------------------
'Fonction récursive.
Private Function Proceed(longueur As Integer, position As Integer, _
Optional str As String)
Dim i As Integer, j As Integer
i = Mid(mvarNumero, position, 1)
If i <> 0 Then
If longueur = 2 Or _
longueur = 5 Or _
longueur = 8 Or _
longueur = 11 Then
' ----
If i = 7 Or i = 9 Then
str = str & m_dixaines(i - 2)
position = position + 1
j = Mid(mvarNumero, position, 1)
If i = 7 And j = 1 Then
str = str & "et " & m_sp(j - 1)
Else
If j <> 0 Then
str = str & m_sp(j - 1)
Else
str = str & "et " & m_dixaines(0)
End If
End If
' ----
longueur = longueur - 1
Else
If i <> 1 Then
str = str & m_dixaines(i - 1)
Else
position = position + 1
j = Mid(mvarNumero, position, 1)
If j > 0 Then
str = str & m_sp(j - 1)
Else
str = str & m_dixaines(j)
End If
longueur = longueur - 1
End If
End If
' ----
Else
If (longueur <> 6 And longueur <> 3 And longueur <> 11) Then
If i <> 1 Then
str = str & m_unites(i - 1)
Else
If position > 1 Then
j = Mid(mvarNumero, position - 1, 1)
If i = 1 And (j > 1 And j < 8) Then str = str & "et "
str = str & m_unites(i - 1)
Else
str = str & m_unites(i - 1)
End If
End If
Else
If i <> 1 Then
str = str & m_unites(i - 1)
End If
End If
End If
End If
' ----
'And Mid(mvarNumero, position + 1) <> 0
If longueur = 4 Then
str = str & M & " "
End If
' ----
If longueur = 7 Then
str = str & IIf(i > 1, G & "s ", G & " ")
End If
' ----
If longueur = 10 Then
str = str & IIf(i > 1, T & "s ", T & " ")
End If
' ----
If (longueur = 3 Or longueur = 6 Or longueur = 9 Or longueur = 12) _
And i <> 0 Then
str = str & C & " "
End If
' ----
' ----
longueur = longueur - 1: position = position + 1
If longueur > 0 Then Proceed longueur, position, str
If Len(str) > 6 Then
str = Trim(str)
If Mid(str, Len(str) - 3, 4) = "Cent" Then
If Mid(mvarNumero, Len(mvarNumero) - 2, 1) > 1 Then
str = str & "s"
End If
End If
If Mid(str, Len(str) - 4, 5) = "Vingt" Then
If Mid(mvarNumero, Len(mvarNumero) - 1, 1) > 1 Then
str = str & "s"
End If
End If
End If
Proceed = str
End Function
Conclusion :
@+, VIC
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.