Access - codigo numero en letras

 
Vista:
Imágen de perfil de JUAN MIGUEL
Val: 29
Ha aumentado su posición en 7 puestos en Access (en relación al último mes)
Gráfica de Access

codigo numero en letras

Publicado por JUAN MIGUEL (50 intervenciones) el 10/05/2015 19:53:15
buen dia , alguien me puede ayudar con este codigo, lo encontre me funciona bien, pero solo me lee los numeros que estan hasta $ 9.999 necesito que me lea los de millones y que termine en centavos
muchas gracias


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
Private Sub Numero_LostFocus()
Dim mil, cen, dec, un, udec, ucen As Integer
Dim total As Double
Texto.Value = ""
mil = 0
cen = 0
dec = 0
un = 0
udec = 0
ucen = 0
total = Numero.Value
Do Until total < 1000
    mil = mil + 1
    total = total - 1000
Loop
Do Until total < 100
    cen = cen + 1
    total = total - 100
Loop
Do Until total < 10
    dec = dec + 1
    total = total - 10
Loop
Do Until total < 1
    un = un + 1
    total = total - 1
Loop
Do Until total < 0.1
    udec = udec + 1
    total = total - 0.1
Loop
Do Until total < 0.009
    ucen = ucen + 1
    total = total - 0.01
Loop
If mil > 1 Then
    nombreunidad (mil)
End If
If mil > 0 Then
    Texto = Texto & " mil"
End If
If cen > 1 Then
    If cen = 5 Then
        Texto = Texto & " quinientos"
    Else
        Texto = Texto & " "
        If cen = 7 Or cen = 9 Then
            nombreunidad (cen * 100)
        Else
            nombreunidad (cen)
        End If
        Texto = Texto & "cientos"
    End If
Else
    If cen = 1 Then
        If dec > 0 Or un > 0 Then
            Texto = Texto & " ciento"
        Else
            Texto = Texto & " cien"
        End If
    End If
End If
If dec > 0 Then
    total = dec * 10 + un
    nombredecena (total)
Else
    If un > 0 Then
        Texto = Texto & " "
        nombreunidad (un)
    End If
End If
If udec > 0 Or ucen > 0 Then
    Texto = Texto & " Pesos con "
    If udec > 0 Then
        total = udec * 10 + ucen
        nombredecena (total)
    Else
        If ucen > 0 Then
            nombreunidad (ucen)
        End If
    End If
End If
End Sub
 
 
Sub nombreunidad(num As Integer)
Select Case num
    Case 1
        Texto = Texto & "uno"
    Case 2
        Texto = Texto & "dos"
    Case 3
        Texto = Texto & "tres"
    Case 4
        Texto = Texto & "cuatro"
    Case 5
        Texto = Texto & "cinco"
    Case 6
        Texto = Texto & "seis"
    Case 7
        Texto = Texto & "siete"
    Case 8
        Texto = Texto & "ocho"
    Case 9
        Texto = Texto & "nueve"
    Case 700
        Texto = Texto & "sete"
    Case 900
        Texto = Texto & "nove"
End Select
End Sub
 
 
 
Sub nombredecena(num As Integer)
Dim dec, un
dec = 0
un = 0
Do Until num < 10
    dec = dec + 1
    num = num - 10
Loop
Do Until num < 1
    un = un + 1
    num = num - 1
Loop
Select Case dec
    Case 1
        Select Case un
            Case 0
                Texto = Texto & " diez"
            Case 1
                Texto = Texto & " once"
            Case 2
                Texto = Texto & " doce"
            Case 3
                Texto = Texto & " trece"
            Case 4
                Texto = Texto & " catorce"
            Case 5
                Texto = Texto & " quince"
            Case 6
                Texto = Texto & " dieciseis"
            Case 7
                Texto = Texto & " diecisiete"
            Case 8
                Texto = Texto & " dieciocho"
            Case 9
                Texto = Texto & " diecinueve"
        End Select
    Case 2
        Texto = Texto & " veint"
        If un = 0 Then
            Texto = Texto & "e"
        Else
            Texto = Texto & "i"
        End If
    Case 3
        Texto = Texto & " treinta"
    Case 4
        Texto = Texto & " cuarenta"
    Case 5
        Texto = Texto & " cincuenta"
    Case 6
        Texto = Texto & " sesenta"
    Case 7
        Texto = Texto & " setenta"
    Case 8
        Texto = Texto & " ochenta"
    Case 9
        Texto = Texto & " noventa"
End Select
If dec > 2 And un > 0 Then
    Texto = Texto & " y "
End If
If dec > 1 And un > 0 Then
    nombreunidad (un)
End If
End Sub
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Norberto
Val: 1.094
Oro
Ha mantenido su posición en Access (en relación al último mes)
Gráfica de Access

codigo numero en letras

Publicado por Norberto (753 intervenciones) el 12/05/2015 14:20:16
Hola.

Echa un vistazo a este post: http://www.lawebdelprogramador.com/foros/Access/1492199-Convertir-numero-a-letra.html. Encontrarás dos soluciones. La mía no convierte decimales pero la puedes usar así:

NúmeroEnLetra = Num2Text(Int(Número)) & " PESOS" & IIf(Número - Int(Número) > 0, " " & Num2Text((Número - Int(Número)) * 100) & " CENTAVOS", "")

Otra cosa. Para evitar errores con los redondeos cambia el comienzo de la función por éste:

1
2
3
4
5
Public Function Num2Text(ByVal value As Double) As String
    value = Round(value, 0)
    Select Case value
        Case 0: Num2Text = "CERO"
    ....

O puedes probar la otra.

Un saludo,

Norberto.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar