Foro de elhacker.net

Programación => Programación Visual Basic => Mensaje iniciado por: freddyjose00 en 17 Febrero 2010, 15:27 pm



Título: Lectura de cantidades númericas en Vb6
Publicado por: freddyjose00 en 17 Febrero 2010, 15:27 pm
Buenas..

Alguien me ayuda con esto, que por ejemplo en un texto este una cantidad cualquiera en números y en un label o otro texto se muestre dicha cantidad pero en letras. Espero me entiendan.


Título: Re: Lectura de cantidades númericas en Vb6
Publicado por: Karcrack en 17 Febrero 2010, 16:15 pm
Tendrás que hacerte tu el algoritmo...
Aunque por ahí he visto ya hechos... :rolleyes:


Título: Re: Lectura de cantidades númericas en Vb6
Publicado por: ssccaann43 © en 17 Febrero 2010, 16:18 pm
Freddy, pega esto en un Modulo Bas...

Código
  1. Function MontoEscrito(Monto As Currency) As String
  2.  
  3. Dim AMT As String
  4. Dim n As String
  5. Dim m As String
  6. Dim k As String
  7. Dim L As String
  8. Dim Rtn_String As String * 120
  9.  
  10. n = "Un    Dos   Tres  CuatroCinco Seis  Siete Ocho  Nueve "
  11. m = "Diez      Once      Doce      Trece     Catorce   Quince    Dieciseis DiecisieteDieciocho Diecinueve"
  12. k = "Veinte   Treinta  Cuarenta CincuentaSesenta  Setenta  Ochenta  Noventa  "
  13. L = "Cien         Doscientos   Trescientos  CuatrocientosQuinientos   Seiscientos  Setecientos  Ochocientos  Novecientos  "
  14.  
  15. If Monto = 0 Then
  16.   MontoEscrito = ""
  17.   Exit Function
  18. End If
  19.  
  20. AMT = Format(Monto, "000000000.00")
  21. Rtn_String = ""
  22.  
  23. If Mid(AMT, 1, 1) = 1 Then     ' 100 - 900 MILLONES
  24.   Rtn_String = Trim(Mid(L, ((Mid(AMT, 1, 1) - 1) * 13) + 1, 13))
  25.   If Trim(Mid(AMT, 1, 3)) > "100" Then
  26.      Rtn_String = Trim(Rtn_String) & "to"
  27.   End If
  28. ElseIf Mid(AMT, 1, 1) > 1 Then
  29.   Rtn_String = Trim(Mid(L, ((Mid(AMT, 1, 1) - 1) * 13) + 1, 13))
  30. End If
  31.  
  32. If Mid(AMT, 2, 1) = 1 Then     ' 10 - 99 MILLONES
  33.   Rtn_String = Trim(Rtn_String) & " " & Mid(m, (Mid(AMT, 3, 1) * 10) + 1, 10)
  34. ElseIf Mid(AMT, 2, 1) > 1 Then
  35.   Rtn_String = Trim(Rtn_String) & " " & Mid(k, ((Mid(AMT, 2, 1) - 2) * 9) + 1, 9)
  36.   If Mid(AMT, 3, 1) > 0 Then
  37.      Rtn_String = Trim(Rtn_String) & " y " & Mid(n, ((Mid(AMT, 3, 1) - 1) * 6) + 1, 6)
  38.   End If
  39. ElseIf Mid(AMT, 3, 1) > 0 Then  ' 1 - 9 MILLONES
  40.   Rtn_String = Trim(Rtn_String) & " " & Mid(n, ((Mid(AMT, 3, 1) - 1) * 6) + 1, 6)
  41. End If
  42.  
  43. If Trim(Rtn_String) <> "" Then
  44.   If Mid(AMT, 1, 3) > 1 Then
  45.      Rtn_String = Trim(Rtn_String) & " Millones "
  46.   Else
  47.      Rtn_String = Trim(Rtn_String) & " Millón "
  48.   End If
  49. End If
  50.  
  51. If Mid(AMT, 4, 1) = 1 Then    ' 100 - 900 MIL
  52.   Rtn_String = Trim(Rtn_String) & " " & Trim(Mid(L, ((Mid(AMT, 4, 1) - 1) * 13) + 1, 13))
  53.   If Mid(AMT, 4, 3) > "100" Then
  54.      Rtn_String = Trim(Rtn_String) & "to"
  55.   End If
  56. ElseIf Mid(AMT, 4, 1) > 1 Then
  57.   Rtn_String = Trim(Rtn_String) & " " & Mid(L, (((Mid(AMT, 4, 1) - 1) * 13) + 1), 13)
  58. End If
  59.  
  60. If Mid(AMT, 5, 1) = 1 Then      ' 10 - 19 Miles
  61.   Rtn_String = Trim(Rtn_String) & " " & Mid(m, (((Mid(AMT, 6, 1)) * 10) + 1), 10)
  62. ElseIf Mid(AMT, 5, 1) > 1 Then  ' 20 - 99 Miles
  63.   Rtn_String = Trim(Rtn_String) & " " & Mid(k, (((Mid(AMT, 5, 1) - 2) * 9) + 1), 9)
  64.   If Mid(AMT, 6, 1) > 0 Then   ' 2? - 9? Miles
  65.      Rtn_String = Trim(Rtn_String) & " y " & Mid(n, (((Mid(AMT, 6, 1) - 1) * 6) + 1), 6)
  66.   End If
  67. ElseIf Mid(AMT, 6, 1) > 0 Then   ' 1  - 9 Miles
  68.   Rtn_String = Trim(Rtn_String) & " " & Mid(n, (((Mid(AMT, 6, 1) - 1) * 6) + 1), 6)
  69. End If
  70.  
  71. If Mid(AMT, 1, 6) <> "000000" And Mid(AMT, 4, 3) <> "000" Then
  72.   Rtn_String = Trim(Rtn_String) & " Mil "
  73. End If
  74.  
  75. If Mid(AMT, 7, 1) = 1 Then
  76.   Rtn_String = Trim(Rtn_String) & " " & Mid(L, (((Mid(AMT, 7, 1) - 1) * 13) + 1), 13)
  77.   If Trim(Mid(AMT, 7, 3)) > "100" Then
  78.      Rtn_String = Trim(Rtn_String) & "to"
  79.   End If
  80. ElseIf Mid(AMT, 7, 1) > 1 Then
  81.   Rtn_String = Trim(Rtn_String) & " " & Mid(L, (((Mid(AMT, 7, 1) - 1) * 13) + 1), 13)
  82. End If
  83.  
  84. If Mid(AMT, 8, 1) = 1 Then
  85.   Rtn_String = Trim(Rtn_String) & " " & Mid(m, ((Mid(AMT, 9, 1) * 10) + 1), 10)
  86. ElseIf Mid(AMT, 8, 1) > 1 Then
  87.   Rtn_String = Trim(Rtn_String) & " " & Mid(k, (((Mid(AMT, 8, 1) - 2) * 9) + 1), 9)
  88.   If Mid(AMT, 9, 1) > 0 Then
  89.      Rtn_String = Trim(Rtn_String) & " y " & Mid(n, (((Mid(AMT, 9, 1) - 1) * 6) + 1), 6)
  90.   End If
  91. ElseIf Mid(AMT, 9, 1) > 0 Then
  92.   Rtn_String = Trim(Rtn_String) & " " & Trim(Mid(n, (((Mid(AMT, 9, 1) - 1) * 6) + 1), 6))
  93.   If Mid(AMT, 9, 1) = 1 Then
  94.      Rtn_String = Trim(Rtn_String) & "o"
  95.   End If
  96. End If
  97.  
  98. If Trim(Rtn_String) <> "" Then
  99.   Rtn_String = Trim(Rtn_String) & " con "
  100. End If
  101.  
  102. Rtn_String = Trim(Rtn_String) & " " & Mid(AMT, 11, 2) & "/100"
  103.  
  104.  
  105. MontoEscrito = Rtn_String
  106. End Function
  107.  

Y para mostrarlo...

Código
  1. Label1.Caption = MontoEscrito(CCur(Text1.Text))
  2.  

Si alguien tiene una mejor manera de hacerlo, pues se aceptan aportes... Saludos


Título: Re: Lectura de cantidades númericas en Vb6
Publicado por: freddyjose00 en 17 Febrero 2010, 16:23 pm
Gracia Miguel. Funciona del carajo.  ;-)


Título: Re: Lectura de cantidades númericas en Vb6
Publicado por: GhostLT en 17 Febrero 2010, 16:39 pm
Haber si te sirve este es un ocx
Descarga (http://www.megaupload.com)

Megaupload
Descarga


Título: Re: Lectura de cantidades númericas en Vb6
Publicado por: ssccaann43 © en 17 Febrero 2010, 16:43 pm
Haber si te sirve este es un ocx
Descarga (http://www.megaupload.com)

Megaupload
Descarga


La intención es no usar dependencias.... :silbar:


Título: Re: Lectura de cantidades númericas en Vb6
Publicado por: Hasseds en 17 Febrero 2010, 16:48 pm
Gracias por el modulo SSCCAANN43, creo que me servirá, estas respuestas no se obtienen el todos lo portales, digo en todos los foros... tal vez algunos users de este foro deberian visitar otros portales, digo foros (me equivoqué otra vez) y corregir algunos Horrores, digo errores... no ?


Título: Re: Lectura de cantidades númericas en Vb6
Publicado por: GhostLT en 17 Febrero 2010, 16:54 pm
Aqui esta corregido el link freddyjose00
 (http://www.megaupload.com/?d=RKVANBCE)


Título: Re: Lectura de cantidades númericas en Vb6
Publicado por: ssccaann43 © en 17 Febrero 2010, 16:56 pm
Gracias por el modulo SSCCAANN43, creo que me servirá, estas respuestas no se obtienen el todos lo portales, digo en todos los foros... tal vez algunos users de este foro deberian visitar otros portales, digo foros (me equivoqué otra vez) y corregir algunos Horrores, digo errores... no ?

De nada, la idea es aportar y brindar apoyo a los demas usuarios...!


Título: Re: Lectura de cantidades númericas en Vb6
Publicado por: Hasseds en 17 Febrero 2010, 17:02 pm
De nada, la idea es aportar y brindar apoyo a los demas usuarios...!

+1