CLR: .Net / Mono / Boo / Otros CLR > VB .NET
Pasar De Numeros A Letras
(1/1)
wilcocks1980:
buenas! y feliz año
es un programilla que te coge la cifra,y te lo pasa a cadena.
es decir, si escribes "90" pues te da como resultado "noventa"
pero el problema que tengo es al validar las comas. Si da dos comas seguidas pues no vale, eso si me sale. Lo que no me sale es el validar esto "95,5,6" por ejemlo,,,
aqui os dejo el codigo y lo probais (si entontrais mas validaciones, bienvenidas sean)
el Form tiene 2 textbox (txtNum y txtLetra) y un boton (bConvertir)
--- Código: Text --- Public Class Form1 Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Me.txtNum.Focus() End Sub #Region "Funcion para convertir" Public Function NumText(ByVal valor As Double) As String Select Case valor Case 0 : NumText = "CERO" Case 1 : NumText = "UN" Case 2 : NumText = "DOS" Case 3 : NumText = "TRES" Case 4 : NumText = "CUATRO" Case 5 : NumText = "CINCO" Case 6 : NumText = "SEIS" Case 7 : NumText = "SIETE" Case 8 : NumText = "OCHO" Case 9 : NumText = "NUEVE" Case 10 : NumText = "DIEZ" Case 11 : NumText = "ONCE" Case 12 : NumText = "DOCE" Case 13 : NumText = "TRECE" Case 14 : NumText = "CATORCE" Case 15 : NumText = "QUINCE" Case Is < 20 : NumText = "DIECI" & NumText(valor - 10) Case 20 : NumText = "VEINTE" Case Is < 30 : NumText = "VEINTI" & NumText(valor - 20) Case 30 : NumText = "TREINTA" Case 40 : NumText = "CUARENTA" Case 50 : NumText = "CINCUENTA" Case 60 : NumText = "SESENTA" Case 70 : NumText = "SETENTA" Case 80 : NumText = "OCHENTA" Case 90 : NumText = "NOVENTA" Case Is < 100 : NumText = NumText(Int(valor \ 10) * 10) & " Y " & NumText(valor Mod 10) Case 100 : NumText = "CIEN" Case Is < 200 : NumText = "CIENTO " & NumText(valor - 100) Case 200, 300, 400, 600, 800 : NumText = NumText(Int(valor \ 100)) & "CIENTOS" Case 500 : NumText = "QUINIENTOS" Case 700 : NumText = "SETECIENTOS" Case 900 : NumText = "NOVECIENTOS" Case Is < 1000 : NumText = NumText(Int(valor \ 100) * 100) & " " & NumText(valor Mod 100) Case 1000 : NumText = "MIL" Case Is < 2000 : NumText = "MIL " & NumText(valor Mod 1000) Case Is < 1000000 : NumText = NumText(Int(valor \ 1000)) & " MIL" If valor Mod 1000 Then NumText = NumText & " " & NumText(valor Mod 1000) Case 1000000 : NumText = "UN MILLON" Case Is < 2000000 : NumText = "UN MILLON " & NumText(valor Mod 1000000) Case Is < 1000000000000.0# : NumText = NumText(Int(valor / 1000000)) & " MILLONES " If (valor - Int(valor / 1000000) * 1000000) Then NumText = NumText & " " & NumText(valor - Int(valor / 1000000) * 1000000) Case 1000000000000.0# : NumText = "UN BILLON" Case Is < 2000000000000.0# : NumText = "UN BILLON " & NumText(valor - Int(valor / 1000000000000.0#) * 1000000000000.0#) Case Else : NumText = NumText(Int(valor / 1000000000000.0#)) & " BILLONES" If (valor - Int(valor / 1000000000000.0#) * 1000000000000.0#) Then NumText = NumText & " " & NumText(valor - Int(valor / 1000000000000.0#) * 1000000000000.0#) End Select End Function #End Region #Region "Extras" Private Sub bConvertir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bConvertir.Click Dim aNum() As String, aDecimal As Boolean aDecimal = False If Trim(Me.txtNum.Text) <> "" And IsNumeric(Me.txtNum.Text) Then aNum = Split(Me.txtNum.Text, ",") Me.txtLetra.Text = NumText(aNum(0)) If aNum.Length > 1 Then Me.txtLetra.Text = Me.txtLetra.Text & " CON " & NumText(aNum(1)) aDecimal = True End If If aDecimal Then Me.txtLetra.Text = Me.txtLetra.Text & " CÉNTIMOS DE EURO" Else Me.txtLetra.Text = Me.txtLetra.Text & " EUROS" End If End If End Sub Private Sub bBorrar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bBorrar.Click Me.txtNum.Clear() Me.txtNum.Focus() End Sub#End Region #Region "Validaciones" Private Sub txtNum_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtNum.KeyDown Dim c As Integer = 1 If (e.KeyCode > 47 And e.KeyCode < 57) Or e.KeyCode = 188 Or e.KeyCode = 8 Or e.KeyCode = 46 Or e.KeyCode = 13 Then Select Case e.KeyCode Case 48 To 57 'Numeros Case 96 To 105 'Numeros 2 Case 8 'bakspace Case 46 'delete Case 13 'intro Me.bConvertir.PerformClick() Case 188 'coma For j As Integer = 1 To Len(txtNum.Text) If Mid$(txtNum.Text, j, 1) = "," Then c = c + 1 If c > 1 Then txtNum.Text = Mid(txtNum.Text, 1, Len(txtNum.Text) - 1) txtNum.SelectionStart = Len(txtNum.Text) Exit For End If End If Next j Case Else ' 'txtNum.Text = Mid(txtNum.Text, 1, Len(txtNum.Text) - 1) ' 'txtNum.SelectionStart = Len(txtNum.Text) End Select Else MessageBox.Show("Sólo se permiten Números") txtNum.Text = Mid(txtNum.Text, 1, Len(txtNum.Text) - 1) txtNum.SelectionStart = Len(txtNum.Text) e.Handled = True End If End Sub#End Region End Class
gracias! :hola:
Navegación
Ir a la versión completa