agrega un modulo a tu base de datos y pega el siguiente codigo
>>>>>>>>>>>>>>>>
Option Explicit
Global gOpcionMil As Boolean
Public vcDesc As String
Public Function vcDescripcion(ByVal Txt As TextBox, ByVal Desc As String)
Txt = Desc
End Function
Public Function Redondear(dblnToR As String, Optional intCntDec As Integer) As String
Dim dblPot As String
Dim dblF As String
If dblnToR < 0 Then dblF = -0.5 Else: dblF = 0.5
dblPot = 10 ^ intCntDec
Redondear = Fix(dblnToR * dblPot * (1 + 1E-16) + dblF) / dblPot
End Function
Public Function EnLetras(numero As String) As String
Dim BandBilion As Boolean
Dim b, paso, cifra As Integer
Dim expresion, entero, deci, flag, valor As String
flag = "N"
'** AQUI REVISAMOS SI EL MONTO TIENE PARTE DECIMAL.
For paso = 1 To Len(numero) 'Determina cuantos caracteres tiene la cadena
If Mid(numero, paso, 1) = "." Or Mid(numero, paso, 1) = "," Then 'dependiendo de la región
flag = "S"
Else
If flag = "N" Then
entero = entero + Mid(numero, paso, 1) 'Extae la parte entera del numero
Else
deci = deci + Mid(numero, paso, 1) 'Extrae la parte decimal del numero
End If
End If
Next paso
'DEFINIMOS VALOR EN LAS VARIABLES
'CIFRA Y VALOR PARA USARLAS COMO
'BANDERAS CONDICIONALES.
cifra = Len(entero)
Select Case cifra
Case Is = 1
valor = "unidad" 'Sin usar
Case Is = 2
valor = "decenas" 'Sin usar
Case Is = 3
valor = "centenas" 'Sin usar
Case Is = 4, 5, 6
valor = "MILES" 'Usado
Case Is = 7, 8, 9
valor = "MILION" 'Usado
Case Is = 10, 11, 12
valor = "MILLARDOS" 'Usado
Case Is = 13, 14, 15
valor = "BILLONES" 'Usado
End Select
'*** SI LA CIFRA TIENE VALOR DECIMAL LO ASIGNAMOS AQUI.
If Len(deci) >= 1 Then
If Len(deci) = 1 Then deci = deci & "0"
deci = deci & "/100." 'Antes tenia & "0" "/100."
Else
deci = "00/100."
End If
flag = "N"
If Val(numero) >= -999999999999999# And Val(numero) <= 999999999999999# Then 'si el numero esta dentro de 0 a 999.999.999
For paso = Len(entero) To 1 Step -1
b = Len(entero) - (paso - 1)
Select Case paso
Case 3, 6, 9, 12, 15
Select Case Mid(entero, b, 1)
Case "1"
If Mid(entero, b + 1, 1) = "0" And Mid(entero, b + 2, 1) = "0" Then
expresion = expresion & "CIEN "
Else
expresion = expresion & "CIENTO "
End If
Case "2"
expresion = expresion & "DOSCIENTOS "
Case "3"
expresion = expresion & "TRESCIENTOS "
Case "4"
expresion = expresion & "CUATROCIENTOS "
Case "5"
expresion = expresion & "QUINIENTOS "
Case "6"
expresion = expresion & "SEISCIENTOS "
Case "7"
expresion = expresion & "SETECIENTOS "
Case "8"
expresion = expresion & "OCHOCIENTOS "
Case "9"
expresion = expresion & "NOVECIENTOS "
End Select
Case 2, 5, 8, 11, 14
Select Case Mid(entero, b, 1)
Case "1"
If Mid(entero, b + 1, 1) = "0" Then
flag = "S"
expresion = expresion & "DIEZ "
End If
If Mid(entero, b + 1, 1) = "1" Then
flag = "S"
expresion = expresion & "ONCE "
End If
If Mid(entero, b + 1, 1) = "2" Then
flag = "S"
expresion = expresion & "DOCE "
End If
If Mid(entero, b + 1, 1) = "3" Then
flag = "S"
expresion = expresion & "TRECE "
End If
If Mid(entero, b + 1, 1) = "4" Then
flag = "S"
expresion = expresion & "CATORCE "
End If
If Mid(entero, b + 1, 1) = "5" Then
flag = "S"
expresion = expresion & "QUINCE "
End If
If Mid(entero, b + 1, 1) > "5" Then
flag = "N"
expresion = expresion & "DIECI"
End If
Case "2"
If Mid(entero, b + 1, 1) = "0" Then
expresion = expresion & "VEINTE "
flag = "S"
Else
expresion = expresion & "VEINTI"
flag = "N"
End If
Case "3"
If Mid(entero, b + 1, 1) = "0" Then
expresion = expresion & "TREINTA "
flag = "S"
Else
expresion = expresion & "TREINTA y "
flag = "N"
End If
Case "4"
If Mid(entero, b + 1, 1) = "0" Then
expresion = expresion & "CUARENTA "
flag = "S"
Else
expresion = expresion & "CUARENTA Y "
flag = "N"
End If
Case "5"
If Mid(entero, b + 1, 1) = "0" Then
expresion = expresion & "CINCUENTA "
flag = "S"
Else
expresion = expresion & "CINCUENTA Y "
flag = "N"
End If
Case "6"
If Mid(entero, b + 1, 1) = "0" Then
expresion = expresion & "SESENTA "
flag = "S"
Else
expresion = expresion & "SESENTA Y "
flag = "N"
End If
Case "7"
If Mid(entero, b + 1, 1) = "0" Then
expresion = expresion & "SETENTA "
flag = "S"
Else
expresion = expresion & "SETENTA Y "
flag = "N"
End If
Case "8"
If Mid(entero, b + 1, 1) = "0" Then
expresion = expresion & "OCHENTA "
flag = "S"
Else
expresion = expresion & "OCHENTA Y "
flag = "N"
End If
Case "9"
If Mid(entero, b + 1, 1) = "0" Then
expresion = expresion & "NOVENTA "
flag = "S"
Else
expresion = expresion & "NOVENTA Y "
flag = "N"
End If
Case "0"
'expresion = expresion & ""
flag = "N"
End Select
Case 1, 4, 7, 10, 13
Select Case Mid(entero, b, 1)
Case "1"
If flag = "N" Then
If paso = 1 Then
expresion = expresion & "UN "
Else
expresion = expresion & "UN "
End If
End If
Case "2"
If flag = "N" Then
expresion = expresion & "DOS "
End If
Case "3"
If flag = "N" Then
expresion = expresion & "TRES "
End If
Case "4"
If flag = "N" Then
expresion = expresion & "CUATRO "
End If
Case "5"
If flag = "N" Then
expresion = expresion & "CINCO "
End If
Case "6"
If flag = "N" Then
expresion = expresion & "SEIS "
End If
Case "7"
If flag = "N" Then
expresion = expresion & "SIETE "
End If
Case "8"
If flag = "N" Then
expresion = expresion & "OCHO "
End If
Case "9"
If flag = "N" Then
expresion = expresion & "NUEVE "
End If
End Select
End Select
'*************************************************************************
'********* MILES PARA MILES
If paso = 4 And valor = "MILES" Then
If Mid(entero, 6, 1) <> "0" Or Mid(entero, 5, 1) <> "0" Or Mid(entero, 4, 1) <> "0" Or _
(Mid(entero, 6, 1) = "0" And Mid(entero, 5, 1) = "0" And Mid(entero, 4, 1) = "0" And _
Len(entero) <= 6) Then
expresion = expresion & "MIL "
End If
End If
'********** MILES PARA MILLONES
If paso = 4 And valor = "MILLON" Then
If cifra = 7 And Val(Mid(entero, 2, 3)) >= 1 Then
expresion = expresion & "MIL "
End If
If cifra = 8 And Val(Mid(entero, 3, 3)) >= 1 Then
expresion = expresion & "MIL "
End If
If cifra = 9 And Val(Mid(entero, 4, 3)) >= 1 Then
expresion = expresion & "MIL "
End If
End If
'********** MILES PARA MILLARDOS
If paso = 4 And valor = "MILLARDOS" Then
If cifra = 10 And Val(Mid(entero, 5, 3)) >= 1 Then
expresion = expresion & "MIL "
End If
If cifra = 11 And Val(Mid(entero, 6, 3)) >= 1 Then
expresion = expresion & "MIL "
End If
If cifra = 12 And Val(Mid(entero, 7, 3)) >= 1 Then
expresion = expresion & "MIL "
End If
End If
'********** MILES PARA BILLONES
If paso = 4 And valor = "BILLONES" Then
If cifra = 13 And Val(Mid(entero, 8, 3)) >= 1 Then
expresion = expresion & "MIL "
End If
If cifra = 14 And Val(Mid(entero, 9, 3)) >= 1 Then
expresion = expresion & "MIL "
End If
If cifra = 15 And Val(Mid(entero, 10, 3)) >= 1 Then
expresion = expresion & "MIL "
End If
End If
'**********"INICIAMOS CONDICIONES PARA USAR PALABRA MILES DE MILLONES"*****************
Select Case gOpcionMil
Case True 'Desea usar la palabra MILES de millones
'Z********[SOLO PARA MILLARDOS] CUANDO MILLONES ES IGUAL A CERO
If paso = 7 And valor = "MILLARDOS" And cifra = 10 _
And Val(Mid(entero, 2, 3)) = 0 Then
expresion = expresion & "MILLONES "
End If
If paso = 7 And valor = "MILLARDOS" And cifra = 11 _
And Val(Mid(entero, 3, 3)) = 0 Then
expresion = expresion & "MILLONES "
End If
If paso = 7 And valor = "MILLARDOS" And cifra = 12 _
And Val(Mid(entero, 4, 3)) = 0 Then
expresion = expresion & "MILLONES "
End If
'Z*****PONER MILLARDOS DE BILLONES ******
If paso = 10 And valor = "BILLONES" And cifra = 13 _
And Val(Mid(entero, 2, 3)) > 0 Then
expresion = expresion & "MIL "
BandBilion = True
End If
If paso = 10 And valor = "BILLONES" And cifra = 14 _
And Val(Mid(entero, 3, 3)) > 0 Then
expresion = expresion & "MIL "
BandBilion = True
End If
If paso = 10 And valor = "BILLONES" And cifra = 15 _
And Val(Mid(entero, 4, 3)) > 0 Then
expresion = expresion & "MIL "
BandBilion = True
End If
'Z******** SOLO PARA BILLONES CUANDO MILLARDOS ES MAS DE CERO
If paso = 7 And valor = "BILLONES" And cifra = 13 _
And Val(Mid(entero, 5, 3)) = 0 And BandBilion Then
expresion = expresion & "MILLONES "
BandBilion = False
End If
If paso = 7 And valor = "BILLONES" And cifra = 14 _
And Val(Mid(entero, 6, 3)) = 0 And BandBilion Then
expresion = expresion & "MILLONES "
BandBilion = False
End If
If paso = 7 And valor = "BILLONES" And cifra = 15 _
And Val(Mid(entero, 7, 3)) = 0 And BandBilion Then
expresion = expresion & "MILLONES "
BandBilion = False
End If
'Z********** SOLO PARA MILLARDOS PRONUNCIADOS EN MILES DE MILLONES.
If paso = 10 And valor = "MILLARDOS" Then
expresion = expresion & "MIL "
End If
'**********"TERMINAMOS CONDICIONES PARA USAR PALABRA MILES DE MILLONES"**********
'**********"INICIAMOS CONDICIONES PARA USAR PALABRA MILLARDO(S)"**********
Case Else ' Desea usar la palabra millardos
If paso = 10 And valor = "BILLONES" And cifra = 13 _
And Val(Mid(entero, 2, 3)) > 0 Then
If Val(Mid(entero, 2, 3)) = 1 Then
expresion = expresion & "MILLARDO "
Else
expresion = expresion & "MILLARDOS "
End If
End If
If paso = 10 And valor = "BILLONES" And cifra = 14 _
And Val(Mid(entero, 3, 3)) > 0 Then
If Val(Mid(entero, 3, 3)) = 1 Then
expresion = expresion & "MILLARDO "
Else
expresion = expresion & "MILLARDOS "
End If
End If
If paso = 10 And valor = "BILLONES" And cifra = 15 _
And Val(Mid(entero, 4, 3)) > 0 Then
If Val(Mid(entero, 4, 3)) = 1 Then
expresion = expresion & "MILLARDO "
Else
expresion = expresion & "MILLARDOS "
End If
End If
'********** MILLARDOS
If paso = 10 And valor = "MILLARDOS" Then
If Len(entero) = 10 And Mid(entero, 1, 1) = "1" Then
expresion = expresion & "MILLARDO "
Else
expresion = expresion & "MILLARDOS "
End If
End If
'**********"TERMINAMOS CONDICIONES PARA USAR PALABRA MILLARDO(S)"**********
'**************************************************************************
End Select
'*******[SOLO PARA MILLARDOS] CUANDO MILLONES ES MAS DE CERO
If paso = 7 And valor = "MILLARDOS" And cifra = 10 And _
Val(Mid(entero, 2, 3)) > 0 Then
If Val(Mid(entero, 2, 3)) = 1 Then
expresion = expresion & "MILLON "
Else
expresion = expresion & "MILLONES "
End If
End If
If paso = 7 And valor = "MILLARDOS" And cifra = 11 _
And Val(Mid(entero, 3, 3)) > 0 Then
If Val(Mid(entero, 3, 3)) = 1 Then
expresion = expresion & "MILLON "
Else
expresion = expresion & "MILLONES "
End If
End If
If paso = 7 And valor = "MILLARDOS" And cifra = 12 _
And Val(Mid(entero, 4, 3)) > 0 Then
If Val(Mid(entero, 4, 3)) = 1 Then
expresion = expresion & "MILLON "
Else
expresion = expresion & "MILLONES "
End If
End If
'*************************************************
'******** SOLO BILLONES
If paso = 7 And valor = "BILLONES" And cifra = 13 _
And Val(Mid(entero, 5, 3)) > 0 Then
If Val(Mid(entero, 5, 3)) = 1 Then
expresion = expresion & "MILLON "
Else
expresion = expresion & "MILLONES "
End If
End If
If paso = 7 And valor = "BILLONES" And cifra = 14 _
And Val(Mid(entero, 6, 3)) > 0 Then
If Val(Mid(entero, 6, 3)) = 1 Then
expresion = expresion & "MILLON "
Else
expresion = expresion & "MILLONES "
End If
End If
If paso = 7 And valor = "BILLONES" And cifra = 15 _
And Val(Mid(entero, 7, 3)) > 0 Then
If Val(Mid(entero, 7, 3)) = 1 Then
expresion = expresion & "MILLON "
Else
expresion = expresion & "MILLONES "
End If
End If
'****************************************************
'********** SOLO PARA MILLONES
If paso = 7 And valor = "MILION" Then
If Len(entero) = 7 And Mid(entero, 1, 1) = "1" Then
expresion = expresion & "MILLON "
Else
expresion = expresion & "MILLONES "
End If
End If
'******** SOLO PARA BILLONES
If paso = 13 Then
If Len(entero) = 13 And Mid(entero, 1, 1) = "1" Then
expresion = expresion & "BILLON "
Else
expresion = expresion & "BILLONES "
End If
End If
Next paso
'*** EVALUAR QUE ESCRIBIR
If deci <> "" Then 'SI EL VALOR RESULTANTE ES NEGATIVO CON DECIMAL
If Mid(entero, 1, 1) = "-" Or Mid(entero, 1, 1) = "(" Then
EnLetras = "MENOS " & expresion & "PESOS " & deci 'ANTES & "/100"
Else
EnLetras = expresion & "PESOS " & deci 'ANTES & "/100"
End If
Else 'SI EL VALOR RESULTANTE ES NEGATIVO SIN DECIMAL
If Mid(entero, 1, 1) = "-" Or Mid(entero, 1, 1) = "(" Then
EnLetras = "MENOS " & expresion
Else
EnLetras = expresion 'si no tiene decimal
End If
End If
If Val(numero) = 0 Then EnLetras = "Monto es igual a cero." 'NO DEBERÍA LLEAGR AQUI
Else 'si el numero a convertir está fuera del rango superior o inferior
EnLetras = "Error en el dato introducido"
End If
End Function
>>>>>>>>>>>>>>
ahora en el textbox o etiqueta donde quieras que aparesca la descripcion debes escribirlo asi
<<<<<<<<<<<<<<<<
='('+EnLetras(Redondear([TxtmnTotal],2))+'MN'+')'
<<<<<<<<<<<<<<<<<
y listo
ok, Suerte
2006-09-04 03:23:34
·
answer #2
·
answered by Francisco Bb 1
·
0⤊
0⤋