elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Introducción a la Factorización De Semiprimos (RSA)


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  necesito orientación sobre programación, me ayuda alguien ?
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: 1 [2] 3 Ir Abajo Respuesta Imprimir
Autor Tema: necesito orientación sobre programación, me ayuda alguien ?  (Leído 7,878 veces)
PROFENIX

Desconectado Desconectado

Mensajes: 18


Ver Perfil
Re: necesito orientación sobre programación, me ayuda alguien ?
« Respuesta #10 en: 25 Diciembre 2018, 22:02 pm »

me e puesto a añadir los nuevos textbox y demas cosas pero cuando e añadido lo que serian los billetes de 10 no se porque demonios no hace la operacion correspondiente.

Código
  1. Public Class Form1
  2.  
  3.    Private Inicializado As Boolean
  4.  
  5.    Private Sub txtBillete50_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtBillete50.TextChanged, txtBillete20.TextChanged, txtBillete10.TextChanged, txtBillete5.TextChanged, txtMonedas2.TextChanged, txtMonedas1.TextChanged, txtMonedas050.TextChanged, txtMonedas020.TextChanged, txtMonedas010.TextChanged, txtMonedas005.TextChanged, txtMonedas002.TextChanged, txtMonedas001.TextChanged
  6.        sender.backcolor = Color.White
  7.        txtTotal.Visible = True
  8.    End Sub
  9.  
  10.    Private Sub txtBillete50_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtBillete50.Validated, txtBillete20.Validated, txtBillete10.Validated, txtBillete5.Validated, txtMonedas2.Validated, txtMonedas1.Validated, txtMonedas050.Validated, txtMonedas020.Validated, txtMonedas010.Validated, txtMonedas005.Validated, txtMonedas002.Validated, txtMonedas001.Validated
  11.        sender.backcolor = Color.White
  12.        txtTotal.Visible = True
  13.    End Sub
  14.  
  15.    Private Sub txtBillete50_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtBillete50.Validating
  16.        Dim v As UShort  'UInt16 entero de 16 bits (valor en el rango: 0-65536)
  17.        ' si admite un valor negativo, cambia al tipo short (int16)
  18.  
  19.        If UShort.TryParse(txtBillete50.Text, v) = False Then
  20.            e.Cancel = True
  21.            Call MessageBox.Show("No puede tomarse como un numero el valor para 'billete de 50'.", "Error: No es un numero.", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  22.            'txtImporte50.Text ="0"
  23.        Else
  24.            txtImporte50.Text = (v * 50).ToString
  25.        End If
  26.    End Sub
  27.  
  28.    Private Sub txtBillete20_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtBillete20.Validating
  29.        Dim v As UShort
  30.        If UShort.TryParse(txtBillete20.Text, v) = False Then
  31.            e.Cancel = True
  32.            Call MessageBox.Show("No puede tomarse como un numero el valor para 'billete de 20'.", "Error: No es un numero.", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  33.        Else
  34.            txtImporte20.Text = (v * 20).ToString
  35.        End If
  36.    End Sub
  37.  
  38.    Private Sub txtBillete10_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)
  39.        Dim v As UShort
  40.        If UShort.TryParse(txtBillete10.Text, v) = False Then
  41.            e.Cancel = True
  42.            Call MessageBox.Show("No puede tomarse como un numero el valor para 'billete de 10'.", "Error: No es un numero.", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  43.        Else
  44.            txtImporte10.Text = (v * 10).ToString
  45.        End If
  46.    End Sub
  47.  
  48.    Private Sub Totalizar() Handles txtImporte50.TextChanged, txtImporte20.TextChanged, txtImporte10.TextChanged
  49.        Dim CantidadTotal As Single  ' entero de 32 bits...
  50.  
  51.        If (Inicializado = True) Then
  52.            CantidadTotal = 0
  53.            CantidadTotal += Single.Parse(txtImporte50.Text)
  54.            CantidadTotal += Single.Parse(txtImporte20.Text)
  55.            CantidadTotal += Single.Parse(txtImporte10.Text)
  56.  
  57.            txtTotal.Text = CantidadTotal.ToString
  58.        End If
  59.    End Sub


« Última modificación: 25 Diciembre 2018, 22:08 pm por PROFENIX » En línea

PROFENIX

Desconectado Desconectado

Mensajes: 18


Ver Perfil
Re: necesito orientación sobre programación, me ayuda alguien ?
« Respuesta #11 en: 25 Diciembre 2018, 23:42 pm »

vale despues de muchos intentos y demas movidas ya lo tengo conseguido a continuacion el codigo y la aplicacion

https://www.justbeamit.com/tgk55

Código
  1. Public Class Form1
  2.  
  3.    Private Inicializado As Boolean
  4.  
  5.    Private Sub txtBillete50_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtBillete50.TextChanged, txtBillete20.TextChanged, txtBillete10.TextChanged, txtBillete5.TextChanged, txtMonedas2.TextChanged, txtMonedas1.TextChanged, txtMonedas050.TextChanged, txtMonedas020.TextChanged, txtMonedas010.TextChanged, txtMonedas005.TextChanged, txtMonedas002.TextChanged, txtMonedas001.TextChanged
  6.        sender.backcolor = Color.White
  7.        txtTotal.Visible = True
  8.    End Sub
  9.  
  10.    Private Sub txtBillete50_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtBillete50.Validated, txtBillete20.Validated, txtBillete10.Validated, txtBillete5.Validated, txtMonedas2.Validated, txtMonedas1.Validated, txtMonedas050.Validated, txtMonedas020.Validated, txtMonedas010.Validated, txtMonedas005.Validated, txtMonedas002.Validated, txtMonedas001.Validated
  11.        sender.backcolor = Color.White
  12.        txtTotal.Visible = True
  13.    End Sub
  14.  
  15.    Private Sub txtBillete50_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtBillete50.Validating
  16.        Dim v As UShort  'UInt16 entero de 16 bits (valor en el rango: 0-65536)
  17.        ' si admite un valor negativo, cambia al tipo short (int16)
  18.  
  19.        If UShort.TryParse(txtBillete50.Text, v) = False Then
  20.            e.Cancel = True
  21.            Call MessageBox.Show("No puede tomarse como un numero el valor para 'billete de 50'.", "Error: No es un numero.", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  22.            'txtImporte50.Text ="0"
  23.        Else
  24.            txtImporte50.Text = (v * 50).ToString
  25.        End If
  26.    End Sub
  27.  
  28.    Private Sub txtBillete20_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtBillete20.Validating
  29.        Dim v As UShort
  30.        If UShort.TryParse(txtBillete20.Text, v) = False Then
  31.            e.Cancel = True
  32.            Call MessageBox.Show("No puede tomarse como un numero el valor para 'billete de 20'.", "Error: No es un numero.", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  33.        Else
  34.            txtImporte20.Text = (v * 20).ToString
  35.        End If
  36.    End Sub
  37.  
  38.    Private Sub txtBillete10_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtBillete10.Validating
  39.        Dim v As UShort
  40.        If UShort.TryParse(txtBillete10.Text, v) = False Then
  41.            e.Cancel = True
  42.            Call MessageBox.Show("No puede tomarse como un numero el valor para 'billete de 10'.", "Error: No es un numero.", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  43.        Else
  44.            txtImporte10.Text = (v * 10).ToString
  45.        End If
  46.    End Sub
  47.  
  48.    Private Sub txtBillete5_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtBillete5.Validating
  49.        Dim v As UShort
  50.        If UShort.TryParse(txtBillete5.Text, v) = False Then
  51.            e.Cancel = True
  52.            Call MessageBox.Show("No puede tomarse como un numero el valor para 'billete de 5'.", "Error: No es un numero.", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  53.        Else
  54.            txtImporte5.Text = (v * 5).ToString
  55.        End If
  56.    End Sub
  57.  
  58.    Private Sub txtMonedas2_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtMonedas2.Validating
  59.        Dim v As UShort
  60.        If UShort.TryParse(txtMonedas2.Text, v) = False Then
  61.            e.Cancel = True
  62.            Call MessageBox.Show("No puede tomarse como un numero el valor para 'monedas de 2'.", "Error: No es un numero.", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  63.        Else
  64.            txtImporte2.Text = (v * 2).ToString
  65.        End If
  66.    End Sub
  67.  
  68.    Private Sub txtMonedas1_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtMonedas1.Validating
  69.        Dim v As UShort
  70.        If UShort.TryParse(txtMonedas1.Text, v) = False Then
  71.            e.Cancel = True
  72.            Call MessageBox.Show("No puede tomarse como un numero el valor para 'monedas de 1'.", "Error: No es un numero.", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  73.        Else
  74.            txtImporte1.Text = (v * 1).ToString
  75.        End If
  76.    End Sub
  77.  
  78.    Private Sub txtMonedas050_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtMonedas050.Validating
  79.        Dim v As Single
  80.        If Single.TryParse(txtMonedas050.Text, v) = False Then
  81.            e.Cancel = True
  82.            Call MessageBox.Show("No puede tomarse como un numero el valor para 'monedas de 0.50'.", "Error: No es un numero.", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  83.        Else
  84.            txtImporte050.Text = (v * 0.5).ToString
  85.        End If
  86.    End Sub
  87.  
  88.    Private Sub txtMonedas020_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtMonedas020.Validating
  89.        Dim v As Single
  90.        If Single.TryParse(txtMonedas020.Text, v) = False Then
  91.            e.Cancel = True
  92.            Call MessageBox.Show("No puede tomarse como un numero el valor para 'monedas de 0.20'.", "Error: No es un numero.", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  93.        Else
  94.            txtImporte020.Text = (v * 0.2).ToString
  95.        End If
  96.    End Sub
  97.  
  98.    Private Sub txtMonedas010_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtMonedas010.Validating
  99.        Dim v As Single
  100.        If Single.TryParse(txtMonedas010.Text, v) = False Then
  101.            e.Cancel = True
  102.            Call MessageBox.Show("No puede tomarse como un numero el valor para 'monedas de 0.10'.", "Error: No es un numero.", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  103.        Else
  104.            txtImporte010.Text = (v * 0.1).ToString
  105.        End If
  106.    End Sub
  107.  
  108.    Private Sub txtMonedas005_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtMonedas005.Validating
  109.        Dim v As Single
  110.        If Single.TryParse(txtMonedas005.Text, v) = False Then
  111.            e.Cancel = True
  112.            Call MessageBox.Show("No puede tomarse como un numero el valor para 'monedas de 0.05'.", "Error: No es un numero.", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  113.        Else
  114.            txtImporte005.Text = (v * 0.05).ToString
  115.        End If
  116.    End Sub
  117.  
  118.    Private Sub txtMonedas002_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtMonedas002.Validating
  119.        Dim v As Single
  120.        If Single.TryParse(txtMonedas002.Text, v) = False Then
  121.            e.Cancel = True
  122.            Call MessageBox.Show("No puede tomarse como un numero el valor para 'monedas de 0.02'.", "Error: No es un numero.", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  123.        Else
  124.            txtImporte002.Text = (v * 0.02).ToString
  125.        End If
  126.    End Sub
  127.  
  128.    Private Sub txtMonedas001_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtMonedas001.Validating
  129.        Dim v As Single
  130.        If Single.TryParse(txtMonedas001.Text, v) = False Then
  131.            e.Cancel = True
  132.            Call MessageBox.Show("No puede tomarse como un numero el valor para 'monedas de 0.01'.", "Error: No es un numero.", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  133.        Else
  134.            txtImporte001.Text = (v * 0.01).ToString
  135.        End If
  136.    End Sub
  137.    Private Sub Totalizar() Handles txtImporte50.TextChanged, txtImporte20.TextChanged, txtImporte10.TextChanged
  138.        Dim CantidadTotal As Single  ' entero de 32 bits...
  139.  
  140.        If (Inicializado = True) Then
  141.            CantidadTotal = 0
  142.            CantidadTotal += Single.Parse(txtImporte50.Text)
  143.            CantidadTotal += Single.Parse(txtImporte20.Text)
  144.            CantidadTotal += Single.Parse(txtImporte10.Text)
  145.            CantidadTotal += Single.Parse(txtImporte5.Text)
  146.            CantidadTotal += Single.Parse(txtImporte2.Text)
  147.            CantidadTotal += Single.Parse(txtImporte1.Text)
  148.            CantidadTotal += Single.Parse(txtImporte050.Text)
  149.            CantidadTotal += Single.Parse(txtImporte020.Text)
  150.            CantidadTotal += Single.Parse(txtImporte010.Text)
  151.            CantidadTotal += Single.Parse(txtImporte005.Text)
  152.            CantidadTotal += Single.Parse(txtImporte002.Text)
  153.            CantidadTotal += Single.Parse(txtImporte001.Text)
  154.  
  155.            txtTotal.Text = CantidadTotal.ToString
  156.        End If
  157.    End Sub
  158.  
  159.  
  160.  
  161.    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  162.        Inicializado = True
  163.    End Sub
  164.  
  165.    Private Sub txtBillete50_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtBillete50.KeyPress
  166.        If Asc(e.KeyChar) = 13 Then
  167.            txtBillete20.Focus()
  168.            e.Handled = True
  169.        End If
  170.    End Sub
  171.  
  172.    Private Sub txtBillete20_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtBillete20.KeyPress
  173.        If Asc(e.KeyChar) = 13 Then
  174.            txtBillete10.Focus()
  175.            e.Handled = True
  176.        End If
  177.    End Sub
  178.  
  179.    Private Sub txtBillete10_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtBillete10.KeyPress
  180.        If Asc(e.KeyChar) = 13 Then
  181.            txtBillete5.Focus()
  182.            e.Handled = True
  183.        End If
  184.    End Sub
  185.  
  186.    Private Sub txtBillete5_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtBillete5.KeyPress
  187.        If Asc(e.KeyChar) = 13 Then
  188.            txtMonedas2.Focus()
  189.            e.Handled = True
  190.        End If
  191.    End Sub
  192.  
  193.    Private Sub txtMonedas2_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtMonedas2.KeyPress
  194.        If Asc(e.KeyChar) = 13 Then
  195.            txtMonedas1.Focus()
  196.            e.Handled = True
  197.        End If
  198.    End Sub
  199.    Private Sub txtMonedas1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtMonedas1.KeyPress
  200.        If Asc(e.KeyChar) = 13 Then
  201.            txtMonedas050.Focus()
  202.            e.Handled = True
  203.        End If
  204.    End Sub
  205.  
  206.    Private Sub txtMonedas050_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtMonedas050.KeyPress
  207.        If Asc(e.KeyChar) = 13 Then
  208.            txtMonedas020.Focus()
  209.            e.Handled = True
  210.        End If
  211.    End Sub
  212.  
  213.    Private Sub txtMonedas020_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtMonedas020.KeyPress
  214.        If Asc(e.KeyChar) = 13 Then
  215.            txtMonedas010.Focus()
  216.            e.Handled = True
  217.        End If
  218.    End Sub
  219.  
  220.    Private Sub txtMonedas010_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtMonedas010.KeyPress
  221.        If Asc(e.KeyChar) = 13 Then
  222.            txtMonedas005.Focus()
  223.            e.Handled = True
  224.        End If
  225.    End Sub
  226.  
  227.    Private Sub txtMonedas005_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtMonedas005.KeyPress
  228.        If Asc(e.KeyChar) = 13 Then
  229.            txtMonedas002.Focus()
  230.            e.Handled = True
  231.        End If
  232.    End Sub
  233.  
  234.    Private Sub txtMonedas002_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtMonedas002.KeyPress
  235.        If Asc(e.KeyChar) = 13 Then
  236.            txtMonedas001.Focus()
  237.            e.Handled = True
  238.        End If
  239.    End Sub
  240.    Private Sub txtMonedas001_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtMonedas001.KeyPress
  241.        If Asc(e.KeyChar) = 13 Then
  242.            txtTotal1.Focus()
  243.            e.Handled = True
  244.        End If
  245.    End Sub
  246.    Private Sub Totalizar(sender As Object, e As EventArgs) Handles txtImporte50.TextChanged, txtImporte20.TextChanged, txtImporte10.TextChanged
  247.  
  248.    End Sub
  249. End Class
  250.  

gracias por la ayuda de verdad os los digo.

El unico problemilla que me encuentro es que el icono no se aplicar en la ventana del propio programilla, solo se aplica al ejecutable y no se el porque. pero bueno lo que queria hacer ya esta hecho, nuevamente muchas gracias


« Última modificación: 25 Diciembre 2018, 23:46 pm por PROFENIX » En línea

Serapis
Colaborador
***
Conectado Conectado

Mensajes: 3.350


Ver Perfil
Re: necesito orientación sobre programación, me ayuda alguien ?
« Respuesta #12 en: 26 Diciembre 2018, 01:08 am »

Me alegro que lo hayas podido resolver...

Sin embargo, te hago 1 observación, y es que se puede presentar un problema.
Nos olvidaremos de optimizaciones, te funciona y resulta simple de entender, así te será fácil a futuro de modificar, para ampliar, etc...


El problema que puede aparecer:
----------------------------------------
Al principio, recordarás que para billetes declaramos como tipo de datos para 'v', ushort, esto implica que al tratar de convertir el texto a ushort, rechace cosas que no son números, pero también números negativos y números decimales... perfecto.

...pero en las monedas, si intentas meter en monedas (por ejemplo de 10 centimos) "10.46" te lo aceptará, y sin embargo el número de monedas no pueda ser decimal, el número de monedas siempre debe ser un número entero...
...e igualmente rechazar también valores negativos. También se podría poner "-11" en monedas y al calcular descontaría el valor de esas monedas... pero no creo que quieras aceptar números negativos.

(prueba a poner decimales o negativos en los billetes y verás que no deja, en cambio en las monedas si deja, y no es lo que queremos)

La solución pasa por tratar cada aspecto de la forma específica, la validación por un lado con el tipo sindecimales y sin números negativos, y por otro la asignación al textbox Importe de la derecha... y se puede proceder, de diferente manera. Lo resolvemos muy fácilmente...

Recuerda que entonces, debes cambiar el contenido (solo) de los txtMonedas..._Validating de la misma forma, que trato la de 50 céntimos, aquí:
Igualmente recalco con ---!!!---  donde hay cambios, para que prestes atención en la parte que cambia.
Código
  1.    Private Sub txtMonedas050_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtMonedas050.Validating
  2. '-------------------!!!----
  3.        Dim v As ushort
  4. ' -------- !!! -----
  5.        If ushort.TryParse(txtMonedas050.Text, v) = False Then
  6.            e.Cancel = True
  7.            Call MessageBox.Show("No puede tomarse como un numero el valor para 'monedas de 0.50'.", "Error: No es un numero.", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  8.        Else
  9. ' ------------------------------------!!!---------
  10.            txtImporte050.Text = (0.5 * v).ToString   ' antes: (v * 0.5).ToString
  11.        End If
  12.    End Sub
  13.  

...y definitivamente te funcionará como quieres.


mmm...veo que no has hecho todo lo que te he dicho...
En totalizar tienes que añadir los handles de todos los controles tras cuyo cambio afectan al total:
Código:
Private Sub Totalizar() Handles txtImporte50.TextChanged, txtImporte20.TextChanged, txtImporte10.TextChanged
Detrás de "Handles"... observa que están solo los de los billetes de 50, 20, y 10, faltan los de 5 y los de las monedas...

En cambio en Private Sub txtBillete50_TextChanged(...) y en Private Sub txtBillete50_Validated(...) si que los añadiste, luego entiendo que lo anterior es un olvido...
« Última modificación: 26 Diciembre 2018, 01:11 am por NEBIRE » En línea

PROFENIX

Desconectado Desconectado

Mensajes: 18


Ver Perfil
Re: necesito orientación sobre programación, me ayuda alguien ?
« Respuesta #13 en: 26 Diciembre 2018, 22:20 pm »

vale he hecho los cambios que me has comentado, pero te comento que he encontrado un fallo el cual no se a que se debe. imagino que habrá que programarlo también. es el hecho en que si por ejemplo en los billetes de 50 pones 4 el resultado sera 200 y en la totalización dará 200, pero cuando llegas al billete de 5 y si en un principio pones que hay 5 que serian 25 el resultado en la totalización serian 225, pero si borras los 5 porque eran 6 el resultado te lo da que serian 30 pero en la suma no se efectúa dicho cambio en la operación, no se si me explico.

esta observación la veo que pasa a partir de los billete de 5

https://www.justbeamit.com/zk7mk

Código
  1. Public Class Form1
  2.  
  3.    Private Inicializado As Boolean
  4.  
  5.    Private Sub txtBillete50_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtBillete50.TextChanged, txtBillete20.TextChanged, txtBillete10.TextChanged, txtBillete5.TextChanged, txtMonedas2.TextChanged, txtMonedas1.TextChanged, txtMonedas050.TextChanged, txtMonedas020.TextChanged, txtMonedas010.TextChanged, txtMonedas005.TextChanged, txtMonedas002.TextChanged, txtMonedas001.TextChanged
  6.        sender.backcolor = Color.White
  7.        txtTotal.Visible = True
  8.    End Sub
  9.  
  10.    Private Sub txtBillete50_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtBillete50.Validated, txtBillete20.Validated, txtBillete10.Validated, txtBillete5.Validated, txtMonedas2.Validated, txtMonedas1.Validated, txtMonedas050.Validated, txtMonedas020.Validated, txtMonedas010.Validated, txtMonedas005.Validated, txtMonedas002.Validated, txtMonedas001.Validated
  11.        sender.backcolor = Color.White
  12.        txtTotal.Visible = True
  13.    End Sub
  14.  
  15.    Private Sub txtBillete50_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtBillete50.Validating
  16.        Dim v As UShort  'UInt16 entero de 16 bits (valor en el rango: 0-65536)
  17.        ' si admite un valor negativo, cambia al tipo short (int16)
  18.  
  19.        If UShort.TryParse(txtBillete50.Text, v) = False Then
  20.            e.Cancel = True
  21.            Call MessageBox.Show("No puede tomarse como un numero el valor para 'billete de 50'.", "Error: No es un numero.", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  22.            'txtImporte50.Text ="0"
  23.        Else
  24.            txtImporte50.Text = (v * 50).ToString
  25.        End If
  26.    End Sub
  27.  
  28.    Private Sub txtBillete20_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtBillete20.Validating
  29.        Dim v As UShort
  30.        If UShort.TryParse(txtBillete20.Text, v) = False Then
  31.            e.Cancel = True
  32.            Call MessageBox.Show("No puede tomarse como un numero el valor para 'billete de 20'.", "Error: No es un numero.", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  33.        Else
  34.            txtImporte20.Text = (v * 20).ToString
  35.        End If
  36.    End Sub
  37.  
  38.    Private Sub txtBillete10_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtBillete10.Validating
  39.        Dim v As UShort
  40.        If UShort.TryParse(txtBillete10.Text, v) = False Then
  41.            e.Cancel = True
  42.            Call MessageBox.Show("No puede tomarse como un numero el valor para 'billete de 10'.", "Error: No es un numero.", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  43.        Else
  44.            txtImporte10.Text = (v * 10).ToString
  45.        End If
  46.    End Sub
  47.  
  48.    Private Sub txtBillete5_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtBillete5.Validating
  49.        Dim v As UShort
  50.        If UShort.TryParse(txtBillete5.Text, v) = False Then
  51.            e.Cancel = True
  52.            Call MessageBox.Show("No puede tomarse como un numero el valor para 'billete de 5'.", "Error: No es un numero.", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  53.        Else
  54.            txtImporte5.Text = (v * 5).ToString
  55.        End If
  56.    End Sub
  57.  
  58.    Private Sub txtMonedas2_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtMonedas2.Validating
  59.        Dim v As UShort
  60.        If UShort.TryParse(txtMonedas2.Text, v) = False Then
  61.            e.Cancel = True
  62.            Call MessageBox.Show("No puede tomarse como un numero el valor para 'monedas de 2'.", "Error: No es un numero.", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  63.        Else
  64.            txtImporte2.Text = (v * 2).ToString
  65.        End If
  66.    End Sub
  67.  
  68.    Private Sub txtMonedas1_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtMonedas1.Validating
  69.        Dim v As UShort
  70.        If UShort.TryParse(txtMonedas1.Text, v) = False Then
  71.            e.Cancel = True
  72.            Call MessageBox.Show("No puede tomarse como un numero el valor para 'monedas de 1'.", "Error: No es un numero.", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  73.        Else
  74.            txtImporte1.Text = (v * 1).ToString
  75.        End If
  76.    End Sub
  77.  
  78.    Private Sub txtMonedas050_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtMonedas050.Validating
  79.        Dim v As UShort
  80.        If UShort.TryParse(txtMonedas050.Text, v) = False Then
  81.            e.Cancel = True
  82.            Call MessageBox.Show("No puede tomarse como un numero el valor para 'monedas de 0.50'.", "Error: No es un numero.", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  83.        Else
  84.            txtImporte050.Text = (0.5 * v).ToString
  85.        End If
  86.    End Sub
  87.  
  88.    Private Sub txtMonedas020_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtMonedas020.Validating
  89.        Dim v As UShort
  90.        If UShort.TryParse(txtMonedas020.Text, v) = False Then
  91.            e.Cancel = True
  92.            Call MessageBox.Show("No puede tomarse como un numero el valor para 'monedas de 0.20'.", "Error: No es un numero.", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  93.        Else
  94.            txtImporte020.Text = (0.2 * v).ToString
  95.        End If
  96.    End Sub
  97.  
  98.    Private Sub txtMonedas010_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtMonedas010.Validating
  99.        Dim v As UShort
  100.        If UShort.TryParse(txtMonedas010.Text, v) = False Then
  101.            e.Cancel = True
  102.            Call MessageBox.Show("No puede tomarse como un numero el valor para 'monedas de 0.10'.", "Error: No es un numero.", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  103.        Else
  104.            txtImporte010.Text = (0.1 * v).ToString
  105.        End If
  106.    End Sub
  107.  
  108.    Private Sub txtMonedas005_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtMonedas005.Validating
  109.        Dim v As UShort
  110.        If UShort.TryParse(txtMonedas005.Text, v) = False Then
  111.            e.Cancel = True
  112.            Call MessageBox.Show("No puede tomarse como un numero el valor para 'monedas de 0.05'.", "Error: No es un numero.", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  113.        Else
  114.            txtImporte005.Text = (0.05 * v).ToString
  115.        End If
  116.    End Sub
  117.  
  118.    Private Sub txtMonedas002_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtMonedas002.Validating
  119.        Dim v As UShort
  120.        If UShort.TryParse(txtMonedas002.Text, v) = False Then
  121.            e.Cancel = True
  122.            Call MessageBox.Show("No puede tomarse como un numero el valor para 'monedas de 0.02'.", "Error: No es un numero.", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  123.        Else
  124.            txtImporte002.Text = (0.02 * v).ToString
  125.        End If
  126.    End Sub
  127.  
  128.    Private Sub txtMonedas001_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtMonedas001.Validating
  129.        Dim v As UShort
  130.        If UShort.TryParse(txtMonedas001.Text, v) = False Then
  131.            e.Cancel = True
  132.            Call MessageBox.Show("No puede tomarse como un numero el valor para 'monedas de 0.01'.", "Error: No es un numero.", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  133.        Else
  134.            txtImporte001.Text = (0.01 * v).ToString
  135.        End If
  136.    End Sub
  137.    Private Sub Totalizar() Handles txtBillete50.TextChanged, txtBillete20.TextChanged, txtBillete10.TextChanged, txtBillete5.TextChanged, txtMonedas2.TextChanged, txtMonedas1.TextChanged, txtMonedas050.TextChanged, txtMonedas020.TextChanged, txtMonedas010.TextChanged, txtMonedas005.TextChanged, txtMonedas002.TextChanged, txtMonedas001.TextChanged
  138.        Dim CantidadTotal As Single  ' entero de 32 bits...
  139.  
  140.        If (Inicializado = True) Then
  141.            CantidadTotal = 0
  142.            CantidadTotal += Single.Parse(txtImporte50.Text)
  143.            CantidadTotal += Single.Parse(txtImporte20.Text)
  144.            CantidadTotal += Single.Parse(txtImporte10.Text)
  145.            CantidadTotal += Single.Parse(txtImporte5.Text)
  146.            CantidadTotal += Single.Parse(txtImporte2.Text)
  147.            CantidadTotal += Single.Parse(txtImporte1.Text)
  148.            CantidadTotal += Single.Parse(txtImporte050.Text)
  149.            CantidadTotal += Single.Parse(txtImporte020.Text)
  150.            CantidadTotal += Single.Parse(txtImporte010.Text)
  151.            CantidadTotal += Single.Parse(txtImporte005.Text)
  152.            CantidadTotal += Single.Parse(txtImporte002.Text)
  153.            CantidadTotal += Single.Parse(txtImporte001.Text)
  154.  
  155.            txtTotal.Text = CantidadTotal.ToString
  156.        End If
  157.    End Sub
  158.  
  159.  
  160.  
  161.    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  162.        Inicializado = True
  163.    End Sub
  164.  
  165.    Private Sub txtBillete50_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtBillete50.KeyPress
  166.        If Asc(e.KeyChar) = 13 Then
  167.            txtBillete20.Focus()
  168.            e.Handled = True
  169.        End If
  170.    End Sub
  171.  
  172.    Private Sub txtBillete20_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtBillete20.KeyPress
  173.        If Asc(e.KeyChar) = 13 Then
  174.            txtBillete10.Focus()
  175.            e.Handled = True
  176.        End If
  177.    End Sub
  178.  
  179.    Private Sub txtBillete10_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtBillete10.KeyPress
  180.        If Asc(e.KeyChar) = 13 Then
  181.            txtBillete5.Focus()
  182.            e.Handled = True
  183.        End If
  184.    End Sub
  185.  
  186.    Private Sub txtBillete5_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtBillete5.KeyPress
  187.        If Asc(e.KeyChar) = 13 Then
  188.            txtMonedas2.Focus()
  189.            e.Handled = True
  190.        End If
  191.    End Sub
  192.  
  193.    Private Sub txtMonedas2_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtMonedas2.KeyPress
  194.        If Asc(e.KeyChar) = 13 Then
  195.            txtMonedas1.Focus()
  196.            e.Handled = True
  197.        End If
  198.    End Sub
  199.    Private Sub txtMonedas1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtMonedas1.KeyPress
  200.        If Asc(e.KeyChar) = 13 Then
  201.            txtMonedas050.Focus()
  202.            e.Handled = True
  203.        End If
  204.    End Sub
  205.  
  206.    Private Sub txtMonedas050_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtMonedas050.KeyPress
  207.        If Asc(e.KeyChar) = 13 Then
  208.            txtMonedas020.Focus()
  209.            e.Handled = True
  210.        End If
  211.    End Sub
  212.  
  213.    Private Sub txtMonedas020_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtMonedas020.KeyPress
  214.        If Asc(e.KeyChar) = 13 Then
  215.            txtMonedas010.Focus()
  216.            e.Handled = True
  217.        End If
  218.    End Sub
  219.  
  220.    Private Sub txtMonedas010_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtMonedas010.KeyPress
  221.        If Asc(e.KeyChar) = 13 Then
  222.            txtMonedas005.Focus()
  223.            e.Handled = True
  224.        End If
  225.    End Sub
  226.  
  227.    Private Sub txtMonedas005_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtMonedas005.KeyPress
  228.        If Asc(e.KeyChar) = 13 Then
  229.            txtMonedas002.Focus()
  230.            e.Handled = True
  231.        End If
  232.    End Sub
  233.  
  234.    Private Sub txtMonedas002_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtMonedas002.KeyPress
  235.        If Asc(e.KeyChar) = 13 Then
  236.            txtMonedas001.Focus()
  237.            e.Handled = True
  238.        End If
  239.    End Sub
  240.    Private Sub txtMonedas001_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtMonedas001.KeyPress
  241.        If Asc(e.KeyChar) = 13 Then
  242.            txtTotal1.Focus()
  243.            e.Handled = True
  244.        End If
  245.    End Sub
  246.    Private Sub Totalizar(sender As Object, e As EventArgs) Handles txtBillete50.TextChanged, txtBillete20.TextChanged, txtBillete10.TextChanged, txtBillete5.TextChanged, txtMonedas2.TextChanged, txtMonedas1.TextChanged, txtMonedas050.TextChanged, txtMonedas020.TextChanged, txtMonedas010.TextChanged, txtMonedas005.TextChanged, txtMonedas002.TextChanged, txtMonedas001.TextChanged
  247.  
  248.    End Sub
  249.  
  250. End Class
« Última modificación: 26 Diciembre 2018, 22:37 pm por PROFENIX » En línea

Serapis
Colaborador
***
Conectado Conectado

Mensajes: 3.350


Ver Perfil
Re: necesito orientación sobre programación, me ayuda alguien ?
« Respuesta #14 en: 26 Diciembre 2018, 23:55 pm »

vale he hecho los cambios que me has comentado, pero te comento que he encontrado un fallo el cual no se a que se debe. imagino que habrá que programarlo también. es el hecho en que si por ejemplo en los billetes de 50 pones 4 el resultado sera 200 y en la totalización dará 200, pero cuando llegas al billete de 5 y si en un principio pones que hay 5 que serian 25 el resultado en la totalización serian 225, pero si borras los 5 porque eran 6 el resultado te lo da que serian 30 pero en la suma no se efectúa dicho cambio en la operación, no se si me explico.

esta observación la veo que pasa a partir de los billete de 5


Código
  1. Public Class Form1
  2.  
  3.    '.... código previo omitido.
  4.  
  5.    Private Sub Totalizar() Handles txtBillete50.TextChanged, txtBillete20.TextChanged, txtBillete10.TextChanged, txtBillete5.TextChanged, txtMonedas2.TextChanged, txtMonedas1.TextChanged, txtMonedas050.TextChanged, txtMonedas020.TextChanged, txtMonedas010.TextChanged, txtMonedas005.TextChanged, txtMonedas002.TextChanged, txtMonedas001.TextChanged
  6.        Dim CantidadTotal As Single  ' entero de 32 bits...
  7.  
  8.        If (Inicializado = True) Then
  9.            CantidadTotal = 0
  10.            CantidadTotal += Single.Parse(txtImporte50.Text)
  11.            CantidadTotal += Single.Parse(txtImporte20.Text)
  12.            CantidadTotal += Single.Parse(txtImporte10.Text)
  13.            CantidadTotal += Single.Parse(txtImporte5.Text)
  14.            CantidadTotal += Single.Parse(txtImporte2.Text)
  15.            CantidadTotal += Single.Parse(txtImporte1.Text)
  16.            CantidadTotal += Single.Parse(txtImporte050.Text)
  17.            CantidadTotal += Single.Parse(txtImporte020.Text)
  18.            CantidadTotal += Single.Parse(txtImporte010.Text)
  19.            CantidadTotal += Single.Parse(txtImporte005.Text)
  20.            CantidadTotal += Single.Parse(txtImporte002.Text)
  21.            CantidadTotal += Single.Parse(txtImporte001.Text)
  22.  
  23.            txtTotal.Text = CantidadTotal.ToString
  24.        End If
  25.    End Sub
  26.  
  27. '... código intermedio omitido.
  28.  
  29.  
  30.    Private Sub Totalizar(sender As Object, e As EventArgs) Handles txtBillete50.TextChanged, txtBillete20.TextChanged, txtBillete10.TextChanged, txtBillete5.TextChanged, txtMonedas2.TextChanged, txtMonedas1.TextChanged, txtMonedas050.TextChanged, txtMonedas020.TextChanged, txtMonedas010.TextChanged, txtMonedas005.TextChanged, txtMonedas002.TextChanged, txtMonedas001.TextChanged
  31.  
  32.    End Sub
  33.  
  34. End Class

De entrada tienes repetida la función... borra esta segunda que tienes al final del código

Tu problema es que no te ciñes a lo que te dije aqúi:

Citar
Nota también que cuando añades el handles, se indica el objeto (control) y el evento correcto... cualquier equivocación en el objeto o en evento, puede producir resutados inesperados, erróneos, o inexactos, impredecibles... a saber...

Fíjate que en esta rutina los eventos a enganchar, son los de cambio de los textbox de IMPORTE (mira el código que te pasé como si lo tienen así, te lo pongo aquídebajo), y  NO el de los textbox de las CANTIDADES, que has puesto (mira tu rutina más arriba).

 
Código
  1. '------------------------------------------ !!!! ------------ !!! ----
  2.    Private Sub Totalizar() Handles TxtImporte001.TextChanged, txtImporte50.TextChanged, txtImporte20.TextChanged, txtImporteX5.TextChanged
  3.        ' -------------------------!!!---
  4.        Dim CantidadTotal As Single   ' entero de 32 bits...
  5.  
  6.        If (Inicializado = True) Then
  7.            ' ---------------------!!!-----
  8.            CantidadTotal = Single.Parse(txtImporte50.Text)
  9.            CantidadTotal += Single.Parse(txtImporte20.Text)
  10.  
  11.            CantidadTotal += Single.Parse(txtImporteX5.Text)
  12.  
  13.            ' ---!!! -------------------------------!!!------
  14.            CantidadTotal += Single.Parse(TxtImporte001.Text)
  15.  
  16.            txtTotal.Text = CantidadTotal.ToString
  17.        End If
  18.    End Sub
  19.  

Es decir, lo correcto es esto:
     Private Sub Totalizar() Handles TxtImporte50.TextChanged, ...
y no esto que has puesto:
      Private Sub Totalizar() Handles txtBillete50.TextChanged, ...
En línea

PROFENIX

Desconectado Desconectado

Mensajes: 18


Ver Perfil
Re: necesito orientación sobre programación, me ayuda alguien ?
« Respuesta #15 en: 27 Diciembre 2018, 08:16 am »

perdona no es que no me ciña a lo que me digas, es que no me di cuenta. cada vez que me dices que tengo que cambiar algo me voy fijando pero hay cosas que en el primer momento se me escapa no se porque pero lo veo igual y pienso joe pues no se donde esta la diferencia. sigo cambiando cosas y pruebo los cambios y digo esto tira, y pienso sera que hay no tenia que fijarme y yo lo e entendido mal.

bueno creo que ya esta todos los cambios aplicados

Código
  1. Public Class Form1
  2.  
  3.    Private Inicializado As Boolean
  4.  
  5.    Private Sub txtBillete50_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtBillete50.TextChanged, txtBillete20.TextChanged, txtBillete10.TextChanged, txtBillete5.TextChanged, txtMonedas2.TextChanged, txtMonedas1.TextChanged, txtMonedas050.TextChanged, txtMonedas020.TextChanged, txtMonedas010.TextChanged, txtMonedas005.TextChanged, txtMonedas002.TextChanged, txtMonedas001.TextChanged
  6.        sender.backcolor = Color.White
  7.        txtTotal.Visible = True
  8.    End Sub
  9.  
  10.    Private Sub txtBillete50_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtBillete50.Validated, txtBillete20.Validated, txtBillete10.Validated, txtBillete5.Validated, txtMonedas2.Validated, txtMonedas1.Validated, txtMonedas050.Validated, txtMonedas020.Validated, txtMonedas010.Validated, txtMonedas005.Validated, txtMonedas002.Validated, txtMonedas001.Validated
  11.        sender.backcolor = Color.White
  12.        txtTotal.Visible = True
  13.    End Sub
  14.  
  15.    Private Sub txtBillete50_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtBillete50.Validating
  16.        Dim v As UShort  'UInt16 entero de 16 bits (valor en el rango: 0-65536)
  17.        ' si admite un valor negativo, cambia al tipo short (int16)
  18.  
  19.        If UShort.TryParse(txtBillete50.Text, v) = False Then
  20.            e.Cancel = True
  21.            Call MessageBox.Show("No puede tomarse como un numero el valor para 'billete de 50'.", "Error: No es un numero.", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  22.            'txtImporte50.Text ="0"
  23.        Else
  24.            txtImporte50.Text = (v * 50).ToString
  25.        End If
  26.    End Sub
  27.  
  28.    Private Sub txtBillete20_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtBillete20.Validating
  29.        Dim v As UShort
  30.        If UShort.TryParse(txtBillete20.Text, v) = False Then
  31.            e.Cancel = True
  32.            Call MessageBox.Show("No puede tomarse como un numero el valor para 'billete de 20'.", "Error: No es un numero.", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  33.        Else
  34.            txtImporte20.Text = (v * 20).ToString
  35.        End If
  36.    End Sub
  37.  
  38.    Private Sub txtBillete10_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtBillete10.Validating
  39.        Dim v As UShort
  40.        If UShort.TryParse(txtBillete10.Text, v) = False Then
  41.            e.Cancel = True
  42.            Call MessageBox.Show("No puede tomarse como un numero el valor para 'billete de 10'.", "Error: No es un numero.", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  43.        Else
  44.            txtImporte10.Text = (v * 10).ToString
  45.        End If
  46.    End Sub
  47.  
  48.    Private Sub txtBillete5_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtBillete5.Validating
  49.        Dim v As UShort
  50.        If UShort.TryParse(txtBillete5.Text, v) = False Then
  51.            e.Cancel = True
  52.            Call MessageBox.Show("No puede tomarse como un numero el valor para 'billete de 5'.", "Error: No es un numero.", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  53.        Else
  54.            txtImporte5.Text = (v * 5).ToString
  55.        End If
  56.    End Sub
  57.  
  58.    Private Sub txtMonedas2_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtMonedas2.Validating
  59.        Dim v As UShort
  60.        If UShort.TryParse(txtMonedas2.Text, v) = False Then
  61.            e.Cancel = True
  62.            Call MessageBox.Show("No puede tomarse como un numero el valor para 'monedas de 2'.", "Error: No es un numero.", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  63.        Else
  64.            txtImporte2.Text = (v * 2).ToString
  65.        End If
  66.    End Sub
  67.  
  68.    Private Sub txtMonedas1_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtMonedas1.Validating
  69.        Dim v As UShort
  70.        If UShort.TryParse(txtMonedas1.Text, v) = False Then
  71.            e.Cancel = True
  72.            Call MessageBox.Show("No puede tomarse como un numero el valor para 'monedas de 1'.", "Error: No es un numero.", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  73.        Else
  74.            txtImporte1.Text = (v * 1).ToString
  75.        End If
  76.    End Sub
  77.  
  78.    Private Sub txtMonedas050_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtMonedas050.Validating
  79.        Dim v As UShort
  80.        If UShort.TryParse(txtMonedas050.Text, v) = False Then
  81.            e.Cancel = True
  82.            Call MessageBox.Show("No puede tomarse como un numero el valor para 'monedas de 0.50'.", "Error: No es un numero.", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  83.        Else
  84.            txtImporte050.Text = (0.5 * v).ToString
  85.        End If
  86.    End Sub
  87.  
  88.    Private Sub txtMonedas020_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtMonedas020.Validating
  89.        Dim v As UShort
  90.        If UShort.TryParse(txtMonedas020.Text, v) = False Then
  91.            e.Cancel = True
  92.            Call MessageBox.Show("No puede tomarse como un numero el valor para 'monedas de 0.20'.", "Error: No es un numero.", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  93.        Else
  94.            txtImporte020.Text = (0.2 * v).ToString
  95.        End If
  96.    End Sub
  97.  
  98.    Private Sub txtMonedas010_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtMonedas010.Validating
  99.        Dim v As UShort
  100.        If UShort.TryParse(txtMonedas010.Text, v) = False Then
  101.            e.Cancel = True
  102.            Call MessageBox.Show("No puede tomarse como un numero el valor para 'monedas de 0.10'.", "Error: No es un numero.", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  103.        Else
  104.            txtImporte010.Text = (0.1 * v).ToString
  105.        End If
  106.    End Sub
  107.  
  108.    Private Sub txtMonedas005_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtMonedas005.Validating
  109.        Dim v As UShort
  110.        If UShort.TryParse(txtMonedas005.Text, v) = False Then
  111.            e.Cancel = True
  112.            Call MessageBox.Show("No puede tomarse como un numero el valor para 'monedas de 0.05'.", "Error: No es un numero.", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  113.        Else
  114.            txtImporte005.Text = (0.05 * v).ToString
  115.        End If
  116.    End Sub
  117.  
  118.    Private Sub txtMonedas002_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtMonedas002.Validating
  119.        Dim v As UShort
  120.        If UShort.TryParse(txtMonedas002.Text, v) = False Then
  121.            e.Cancel = True
  122.            Call MessageBox.Show("No puede tomarse como un numero el valor para 'monedas de 0.02'.", "Error: No es un numero.", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  123.        Else
  124.            txtImporte002.Text = (0.02 * v).ToString
  125.        End If
  126.    End Sub
  127.  
  128.    Private Sub txtMonedas001_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtMonedas001.Validating
  129.        Dim v As UShort
  130.        If UShort.TryParse(txtMonedas001.Text, v) = False Then
  131.            e.Cancel = True
  132.            Call MessageBox.Show("No puede tomarse como un numero el valor para 'monedas de 0.01'.", "Error: No es un numero.", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  133.        Else
  134.            txtImporte001.Text = (0.01 * v).ToString
  135.        End If
  136.    End Sub
  137.    Private Sub Totalizar() Handles txtImporte50.TextChanged, txtImporte20.TextChanged, txtImporte10.TextChanged, txtImporte5.TextChanged, txtImporte2.TextChanged, txtImporte1.TextChanged, txtImporte050.TextChanged, txtImporte020.TextChanged, txtImporte010.TextChanged, txtImporte005.TextChanged, txtImporte002.TextChanged, txtImporte001.TextChanged
  138.        Dim CantidadTotal As Single  ' entero de 32 bits...
  139.  
  140.        If (Inicializado = True) Then
  141.            CantidadTotal = 0
  142.            CantidadTotal += Single.Parse(txtImporte50.Text)
  143.            CantidadTotal += Single.Parse(txtImporte20.Text)
  144.            CantidadTotal += Single.Parse(txtImporte10.Text)
  145.            CantidadTotal += Single.Parse(txtImporte5.Text)
  146.            CantidadTotal += Single.Parse(txtImporte2.Text)
  147.            CantidadTotal += Single.Parse(txtImporte1.Text)
  148.            CantidadTotal += Single.Parse(txtImporte050.Text)
  149.            CantidadTotal += Single.Parse(txtImporte020.Text)
  150.            CantidadTotal += Single.Parse(txtImporte010.Text)
  151.            CantidadTotal += Single.Parse(txtImporte005.Text)
  152.            CantidadTotal += Single.Parse(txtImporte002.Text)
  153.            CantidadTotal += Single.Parse(txtImporte001.Text)
  154.  
  155.            txtTotal.Text = CantidadTotal.ToString
  156.        End If
  157.    End Sub
  158.  
  159.    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  160.        Inicializado = True
  161.    End Sub
  162.  
  163.    Private Sub txtBillete50_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtBillete50.KeyPress
  164.        If Asc(e.KeyChar) = 13 Then
  165.            txtBillete20.Focus()
  166.            e.Handled = True
  167.        End If
  168.    End Sub
  169.  
  170.    Private Sub txtBillete20_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtBillete20.KeyPress
  171.        If Asc(e.KeyChar) = 13 Then
  172.            txtBillete10.Focus()
  173.            e.Handled = True
  174.        End If
  175.    End Sub
  176.  
  177.    Private Sub txtBillete10_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtBillete10.KeyPress
  178.        If Asc(e.KeyChar) = 13 Then
  179.            txtBillete5.Focus()
  180.            e.Handled = True
  181.        End If
  182.    End Sub
  183.  
  184.    Private Sub txtBillete5_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtBillete5.KeyPress
  185.        If Asc(e.KeyChar) = 13 Then
  186.            txtMonedas2.Focus()
  187.            e.Handled = True
  188.        End If
  189.    End Sub
  190.  
  191.    Private Sub txtMonedas2_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtMonedas2.KeyPress
  192.        If Asc(e.KeyChar) = 13 Then
  193.            txtMonedas1.Focus()
  194.            e.Handled = True
  195.        End If
  196.    End Sub
  197.    Private Sub txtMonedas1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtMonedas1.KeyPress
  198.        If Asc(e.KeyChar) = 13 Then
  199.            txtMonedas050.Focus()
  200.            e.Handled = True
  201.        End If
  202.    End Sub
  203.  
  204.    Private Sub txtMonedas050_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtMonedas050.KeyPress
  205.        If Asc(e.KeyChar) = 13 Then
  206.            txtMonedas020.Focus()
  207.            e.Handled = True
  208.        End If
  209.    End Sub
  210.  
  211.    Private Sub txtMonedas020_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtMonedas020.KeyPress
  212.        If Asc(e.KeyChar) = 13 Then
  213.            txtMonedas010.Focus()
  214.            e.Handled = True
  215.        End If
  216.    End Sub
  217.  
  218.    Private Sub txtMonedas010_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtMonedas010.KeyPress
  219.        If Asc(e.KeyChar) = 13 Then
  220.            txtMonedas005.Focus()
  221.            e.Handled = True
  222.        End If
  223.    End Sub
  224.  
  225.    Private Sub txtMonedas005_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtMonedas005.KeyPress
  226.        If Asc(e.KeyChar) = 13 Then
  227.            txtMonedas002.Focus()
  228.            e.Handled = True
  229.        End If
  230.    End Sub
  231.  
  232.    Private Sub txtMonedas002_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtMonedas002.KeyPress
  233.        If Asc(e.KeyChar) = 13 Then
  234.            txtMonedas001.Focus()
  235.            e.Handled = True
  236.        End If
  237.    End Sub
  238.    Private Sub txtMonedas001_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtMonedas001.KeyPress
  239.        If Asc(e.KeyChar) = 13 Then
  240.            txtTotal1.Focus()
  241.            e.Handled = True
  242.        End If
  243.    End Sub
  244.  
  245. End Class
  246.  
En línea

Serapis
Colaborador
***
Conectado Conectado

Mensajes: 3.350


Ver Perfil
Re: necesito orientación sobre programación, me ayuda alguien ?
« Respuesta #16 en: 27 Diciembre 2018, 15:11 pm »

Bien, pués ahora que parece que ya te funciona todo bien, vamos a hacer una optimización de reducción de código...

La rutina validating... Si te fijas bien, hay una por cada billete y moneda, pero el código que hacen es siempre el mismo... entonces vamos a parametrizar las diferencias para reunirlas en una sola función, y desde todas ellas invocar a esa.

Primero creamos la función que hará el trabajo de todas, y luego vemos de modificar una a modo de ejemplo pero que se aplica a todas (cambiando las diferencias):
Código
  1.    Private Sub ValidandoBiletesyMonedas(ByVal Valor As String, ByVal TxtDestino As TextBox, ByVal FactorConv As Single, ByVal TextoMsg As String, ByVal e As System.ComponentModel.CancelEventArgs)
  2.        Dim v As UShort
  3.  
  4.        If UShort.TryParse(Valor, v) = False Then
  5.            e.Cancel = True
  6.            Call MessageBox.Show("No puede tomarse como un número el valor para" & TextoMsg, "Error: No es un número (entero y positivo).", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  7.        Else
  8.            TxtDestino.Text = (FactorConv * v).ToString
  9.        End If
  10.    End Sub
  11.  

Como ves la rutina hace exactamente lo mismo que hemos venido haciendo en cada una, solo que está es 'universal' para todas ellas... Puede ser llamada desde todas las otras que tienen ese código, con una sola línea en aquellas llamando a esta, con los valores adecuados en sus parámetros...

Ahora te pongo, como se ha cambiado una de ellas, para que de modo similar, apliques el cambio a todas, fijándote bien en los valores que pones en la llamada a esta función recién redactada...
De ejemplo tomamos la de 1 céntimo... nota que dejo comentado el código previo que tenía... te sirve para verificar que los datos que pasas a la función son los mismos que ahí tienes, cuando funciones bien, puedes eliminarlo y estarás eliminando unas 100 líneas de código de un plumazo.
Código
  1. Private Sub txtMonedas001_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TxtBillete001.Validating
  2.        ' sender se refiere siempre al objeto que lo llama, aquí txtMonedas001, poner sender.text es casi lo mismo que poner txtMonedas001.text
  3.        Call ValidandoBiletesyMonedas(sender.text, TxtImporte001, 0.1, " 'monedas de 1 céntimo'.", e)
  4.        'Dim v As UShort 'Single 'UShort
  5.        'If UShort.TryParse(txtMonedas001.Text, v) = False Then
  6.        '    e.Cancel = True
  7.        '    Call MessageBox.Show("No puede tomarse como un número el valor para 'monedas de 1 céntimo'.", "Error: No es un número.", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  8.        'Else
  9.        '    TxtImporte001.Text = (0.1 * v).ToString
  10.        'End If
  11.    End Sub
  12.  

Cuando compruebes que te funcionen bien (porque no equivocaste los valores que se pasan a la función), puedes eliminar el código comentado en cada función, y mira como queda reducido:
Código
  1. Private Sub txtMonedas001_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TxtBillete001.Validating
  2.        Call ValidandoBiletesyMonedas(sender.text, TxtImporte001, 0.1, " 'monedas de 1 céntimo'.", e)
  3.    End Sub
  4.  


p.d.: Cuando hagas esa optimización y te salga bien... sin errores (si quieres, por supuesto), todavía volveremos a optimizarlo más, no solo esa, también las de KeyPress... para que sean remplazas todas por solo 2 funciones en cada caso.
« Última modificación: 27 Diciembre 2018, 15:14 pm por NEBIRE » En línea

PROFENIX

Desconectado Desconectado

Mensajes: 18


Ver Perfil
Re: necesito orientación sobre programación, me ayuda alguien ?
« Respuesta #17 en: 27 Diciembre 2018, 20:35 pm »

lo que me comentas que deberia de cambiar para optimizar seria esta parte del codigo ?

Código
  1. Private Sub txtBillete50_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtBillete50.Validating
  2.        Dim v As UShort  'UInt16 entero de 16 bits (valor en el rango: 0-65536)
  3.        ' si admite un valor negativo, cambia al tipo short (int16)
  4.  
  5.        If UShort.TryParse(txtBillete50.Text, v) = False Then
  6.            e.Cancel = True
  7.            Call MessageBox.Show("No puede tomarse como un numero el valor para 'billete de 50'.", "Error: No es un numero.", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  8.            'txtImporte50.Text ="0"
  9.        Else
  10.            txtImporte50.Text = (v * 50).ToString
  11.        End If
  12.    End Sub

y si es asi te refieres que elimine todos esos codigo y lo sustituya por el que me comentas aqui, pero claro poniendo los nombres de los billetes y monedas que corresponde en cada uno.

Código
  1. Private Sub txtMonedas001_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TxtBillete001.Validating
  2.        Call ValidandoBiletesyMonedas(sender.text, TxtImporte001, 0.1, " 'monedas de 1 céntimo'.", e)
  3.    End Sub

es que esta parte es la que no llego a comprender bien del todo, la verdad y no se si te estas refiriendo a eso o a otra cosa.

P.D. me traido el programita al pc donde se ejecutara para probarlo, y no e tenido una cosa en cuenta no se si sera una metedura de pata muy grande y tendre que comenzar desde 0 o si por el contrario seria una tonteria, el caso es que no lo e pidido ejecutar porque este pc trabaja con windows 2000 de 32 bits y el programita el exe compilado es de 64 bits.

Hay forma sencilla de arreglar eso o tendre que empezar desde 0?
« Última modificación: 28 Diciembre 2018, 10:11 am por PROFENIX » En línea

Serapis
Colaborador
***
Conectado Conectado

Mensajes: 3.350


Ver Perfil
Re: necesito orientación sobre programación, me ayuda alguien ?
« Respuesta #18 en: 29 Diciembre 2018, 00:43 am »

Citar
...y si es asi te refieres que elimine todos esos codigo y lo sustituya por el que me comentas aqui, pero claro poniendo los nombres de los billetes y monedas que corresponde en cada uno...
Exacto, si...

Citar
porque este pc trabaja con windows 2000 de 32 bits y el programita el exe compilado es de 64 bits.
Si el ordenador destino ha de ser fijo un windows 2000, hay que rehacerlo en vb6...
No obstante, no elimines el programa... si tarde o temprano, tienes que usarlo en un equipo más actual, pués ya lo tienes.

Citar
Hay forma sencilla de arreglar eso o tendre que empezar desde 0?
No. Son tecnologías distintas. En windows 2000 incluso es muy probable que no admita ningún framework más actual que el 1.1 o 2.0 de NET (no estoy seguro, habría que mirarlo).
Ya en el XP, la versión superior que admite es el NET 3.5

En fin, básicamente se puede rehacer con VB6, con cambios eso sí... La cuestión es si tienes un IDE de VB6...

« Última modificación: 29 Diciembre 2018, 00:45 am por NEBIRE » En línea

PROFENIX

Desconectado Desconectado

Mensajes: 18


Ver Perfil
Re: necesito orientación sobre programación, me ayuda alguien ?
« Respuesta #19 en: 29 Diciembre 2018, 06:13 am »

Exacto, si...
Si el ordenador destino ha de ser fijo un windows 2000, hay que rehacerlo en vb6...
No obstante, no elimines el programa... si tarde o temprano, tienes que usarlo en un equipo más actual, pués ya lo tienes.
No. Son tecnologías distintas. En windows 2000 incluso es muy probable que no admita ningún framework más actual que el 1.1 o 2.0 de NET (no estoy seguro, habría que mirarlo).
Ya en el XP, la versión superior que admite es el NET 3.5

En fin, básicamente se puede rehacer con VB6, con cambios eso sí... La cuestión es si tienes un IDE de VB6...



lo he compilado en x86 y con la versión framework.net 2.0 que es la mas baja que me permite el visual studio que yo tengo, lo probare hoy. con los resultados que obtenga te lo comentare.

después de intentar ejecutarlo me salta este error



habrá que hacerlo en visual basic finalmente ?

P.D. quiero recordar que ese ordenador no puedo instalar nada. me refiero a si me dices a mira eso instalas tal libreria de dll o lo que sea y se te soluciona. no puedo porque es el ordenador donde yo trabajo y no quiero joderla con los programas que ya maneja el propio ordenador, solo por la cosa de tener este mini programita de calculo.

« Última modificación: 29 Diciembre 2018, 15:42 pm por PROFENIX » En línea

Páginas: 1 [2] 3 Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Necesito orientacion para aprender sobre..
Foro Libre
$Edu$ 3 2,623 Último mensaje 18 Noviembre 2011, 17:40 pm
por $Edu$
Necesito orientación sobre sentencia EXPLAIN
Bases de Datos
Hadess_inf 1 2,040 Último mensaje 18 Abril 2012, 01:47 am
por Shell Root
Necesito información sobre la programacion en red de juegos.
Programación General
anonimo12121 2 1,933 Último mensaje 25 Marzo 2013, 18:32 pm
por anonimo12121
Necesito ayuda y consejo sobre obtener la IP de alguien « 1 2 »
Hacking
scratcho57 13 9,755 Último mensaje 12 Mayo 2015, 16:12 pm
por Hurdano
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines