Nombre: TRASLADAR DE NUMERO A LETRAS
Descripción:
Esencial para hacer cheques facturas, etc.
URL: http://www.mygnet.net/codigos/vb/metodo_y_comandos/trasladar_de_numero_a_letras.1153
Código Fuente:
Option Explicit
Private Function Centena(I As Integer) As String
Centena = Choose(I + 1, "", "ciento", "doscientos", "trescientos", "cuatrocientos", "quinientos", "seiscientos", "setecientos", "ochocientos", "novecientos")
End Function
Private Function Cien(I As Long) As String
Dim TCien As String
TCien = ""
If (I = 100) Then
TCien = "cien"
Else
TCien = Centena(Int(I / 100))
If (I Mod 100) <> 0 Then
If Int(I / 100) <> 0 Then
TCien = TCien & " "
End If
TCien = TCien & Diez(I Mod 100)
End If
End If
Cien = TCien
End Function
Private Function Decena(I As Integer) As String
Decena = Choose(I + 1, "", "", "", "treinta", "cuarenta", "cincuenta", "sesenta", "setenta", "ochenta", "noventa")
End Function
Private Function Diez(I As Integer) As String
Dim TDiez As String
TDiez = ""
If I < 30 Then
TDiez = Excepcion(I)
Else
TDiez = Decena(Int(I / 10))
If (I Mod 10) <> 0 Then
TDiez = TDiez & " y " & Excepcion(I Mod 10)
End If
End If
Diez = TDiez
End Function
Public Function NumeroTexto(ByVal X As Long) As String
Dim texto As String
texto = ""
If X < 2147483647# And X >= 0 Then
texto = texto & Millon(X)
Else
texto = "Numero demasiado grande"
End If
NumeroTexto = texto
End Function
Private Function Excepcion(I As Integer) As String
If I < 10 Then
Excepcion$ = Choose(I + 1, "", "un", "dos", "tres", "cuatro", "cinco", "seis", "siete", "ocho", "nueve")
ElseIf I < 20 Then
Excepcion$ = Choose(I - 9, "diez", "once", "doce", "trece", "catorce", "quince", "dieciséis", "diecisiete", "dieciocho", "diecinueve")
Else
Excepcion$ = Choose(I - 19, "veinte", "veintiun", "veintidos", "veintitres", "veinticuatro", "veinticinco", "veintiseis", "veintisiete", "veintiocho", "veintinueve")
End If
End Function
Private Function Mil(I As Long) As String
Dim TMil As String
If Int(I / 1000) = 1 Then
TMil$ = "mil"
If (I Mod 1000) <> 0 Then
TMil$ = TMil$ & " "
End If
TMil$ = TMil$ & Cien(I Mod 1000)
ElseIf Int(I / 1000) = 0 Then
TMil$ = Cien(I) 'Cambié int(i) por i
Else
TMil$ = Cien(Int(I / 1000)) & " mil"
If (I Mod 1000) <> 0 Then
TMil$ = TMil$ & " "
End If
TMil$ = TMil$ & Cien(I Mod 1000)
End If
Mil$ = TMil$
End Function
Private Function Millon(I As Long) As String
Dim TMillon As String
TMillon = ""
If I >= 0 Then
If I = 0 Then
TMillon = "cero"
ElseIf Int(I / 1000000) = 0 Then
TMillon = Mil(I)
ElseIf Int(I / 1000000) = 1 Then
TMillon = "un millon"
If (I Mod 1000000 <> 0) Then
TMillon = TMillon & " "
End If
TMillon = TMillon & Mil(I Mod 1000000)
Else
TMillon = Mil(Int(I / 1000000)) & " millones"
If (I Mod 1000000 <> 0) Then
TMillon = TMillon & " "
End If
TMillon = TMillon & Mil(I Mod 1000000)
End If
End If
If (I Mod 10 = 1) And (I Mod 100 <> 11) Then
TMillon = TMillon & "o"
End If
Millon = TMillon
End Function
Public Function DineroTexto(ByVal X As Double) As String
Dim texto As String
Dim IntX As Long
Dim FraX As Integer
texto = ""
If X < 2147483647# And X >= 0 Then
IntX = Int(X)
texto = texto + Millon(CLng(IntX))
FraX = Int((X - IntX) * 100 + 0.5)
texto = texto + " " + Format(FraX, "00") + "/100 ctvs."
End If
DineroTexto = texto$
End Function