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

 

 


Tema destacado: Introducción a Git (Primera Parte)


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP) (Moderador: kub0x)
| | | |-+  Como eliminar resultados numericos en un variable o Array ?
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Como eliminar resultados numericos en un variable o Array ?  (Leído 3,143 veces)
luis456


Desconectado Desconectado

Mensajes: 548



Ver Perfil
Como eliminar resultados numericos en un variable o Array ?
« en: 27 Octubre 2013, 09:15 am »

Hola quiero mostrar números dentro de un rango establecido (00 al 99 )

Necesito hacer una función que me elimine lo números que se pasen de 99 ? pero que no me deje los texboxes vacíos ? poniendo el ultimo numero del rango si este se pasa del mismo


Código:
Result1 = {Num1 + 10, Num1 + 20, Num1 + 30} _
                  .Distinct().ToArray '

        Array.Sort(Result1)

 
For Each Number As Int32 In Result1
            TextBoxCount += 1
            TextBoxes(TextBoxCount).Text = Number
        Next


Luis


En línea

Que tu sabiduria no sea motivo de Humillacion para los demas
Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.788



Ver Perfil
Re: Como eliminar resultados numericos en un variable o Array ?
« Respuesta #1 en: 27 Octubre 2013, 12:33 pm »

Código
  1.    Private Sub Test(sender As Object, e As EventArgs) Handles MyBase.Shown
  2.  
  3.        Dim TextBoxes() As TextBox = _
  4.            {TextBox1, TextBox2, TextBox3, TextBox4, TextBox5}
  5.  
  6.        Dim TextBoxCount As Integer = 0
  7.  
  8.        Dim maximum As Short = 99
  9.  
  10.        Dim Result() As Integer = { _
  11.                                    90, _
  12.                                    40, _
  13.                                    50, _
  14.                                    90, _
  15.                                    100, _
  16.                                    125 _
  17.                                  }.Distinct().ToArray
  18.  
  19.        Array.Sort(Result)
  20.  
  21.        For Each Number As Integer In Result
  22.  
  23.            TextBoxes(TextBoxCount).Text = _
  24.                If(Not Number > maximum, _
  25.                   CStr(Number), _
  26.                   CStr(maximum))
  27.  
  28.            Threading.Interlocked.Increment(TextBoxCount)
  29.  
  30.        Next Number
  31.  
  32.    End Sub



Saludos


« Última modificación: 27 Octubre 2013, 12:35 pm por EleKtro H@cker » En línea

luis456


Desconectado Desconectado

Mensajes: 548



Ver Perfil
Re: Como eliminar resultados numericos en un variable o Array ?
« Respuesta #2 en: 27 Octubre 2013, 12:54 pm »

Código
  1.    Private Sub Test(sender As Object, e As EventArgs) Handles MyBase.Shown
  2.  
  3.        Dim TextBoxes() As TextBox = _
  4.            {TextBox1, TextBox2, TextBox3, TextBox4, TextBox5}
  5.  
  6.        Dim TextBoxCount As Integer = 0
  7.  
  8.        Dim maximum As Short = 99
  9.  
  10.        Dim Result() As Integer = { _
  11.                                    90, _
  12.                                    40, _
  13.                                    50, _
  14.                                    90, _
  15.                                    100, _
  16.                                    125 _
  17.                                  }.Distinct().ToArray
  18.  
  19.        Array.Sort(Result)
  20.  
  21.        For Each Number As Integer In Result
  22.  
  23.            TextBoxes(TextBoxCount).Text = _
  24.                If(Not Number > maximum, _
  25.                   CStr(Number), _
  26.                   CStr(maximum))
  27.  
  28.            Threading.Interlocked.Increment(TextBoxCount)
  29.  
  30.        Next Number
  31.  
  32.    End Sub



Saludos


Gracias EleKtro siempre tan amable ahora a ver como adapto esto a mi código :) pensaba que con un simple iff se haria jejeje ya te contare como me va..

Luis


En línea

Que tu sabiduria no sea motivo de Humillacion para los demas
luis456


Desconectado Desconectado

Mensajes: 548



Ver Perfil
Re: Como eliminar resultados numericos en un variable o Array ?
« Respuesta #3 en: 27 Octubre 2013, 13:07 pm »

Ya me pegare un tiro pronto :)


Código
  1. Public Class Form1
  2.  
  3.    Private Property Result1 As Object
  4.  
  5.    ReadOnly Property Num1 As Int32
  6.        Get
  7.            Return CInt(TextBox1.Text)
  8.        End Get
  9.    End Property
  10.    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  11.        Result1 = {Num1 + 15, Num1 + 25} _
  12.                          .Distinct().ToArray ' Elimino duplicados
  13.        For Each Number As Int32 In Result1
  14.            TextBoxCount += 1
  15.            TextBox(TextBoxCount).Text = Number
  16.        Next
  17.    End Sub
  18.    Private Sub Test(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Shown
  19.  
  20.        Dim TextBoxes() As TextBox = _
  21.            {TextBox1, TextBox2, TextBox3, TextBox4, TextBox5}
  22.  
  23.        Dim TextBoxCount As Integer = 0
  24.  
  25.        Dim maximum As Short = 99
  26.  
  27.        Dim Result1 As Integer = { _
  28.                                    90, _
  29.                                    40, _
  30.                                    50, _
  31.                                    90, _
  32.                                    100, _
  33.                                    125 _
  34.                                  }.Distinct().ToArray
  35.  
  36.        Array.Sort(Result1)
  37.  
  38.        For Each Number As Integer In Result1
  39.  
  40.            TextBoxes(TextBoxCount).Text = _
  41.                If(Not Number > maximum, _
  42.                   CStr(Number), _
  43.                   CStr(maximum))
  44.  
  45.            Threading.Interlocked.Increment(TextBoxCount)
  46.  
  47.        Next Number
  48.  
  49.    End Sub
  50.  
  51.    Private Function TextBoxCount() As Object
  52.        Throw New NotImplementedException
  53.    End Function
  54.  
  55.    Private Function TextBox(ByVal p1 As Object) As Object
  56.        Throw New NotImplementedException
  57.    End Function
  58.  
  59. End Class
« Última modificación: 29 Octubre 2013, 14:54 pm por EleKtro H@cker » En línea

Que tu sabiduria no sea motivo de Humillacion para los demas
luis456


Desconectado Desconectado

Mensajes: 548



Ver Perfil
Re: Como eliminar resultados numericos en un variable o Array ?
« Respuesta #4 en: 29 Octubre 2013, 13:50 pm »

No logro hacer nada :) es en este codigo que quiero hacer las limitaciones de numeros

Código
  1. Public Class Form1
  2.  
  3.    Private TextBoxes As TextBox() = {Nothing}
  4.  
  5.    Private Result1 As Int32(), Result2 As Int32()
  6.  
  7.    ReadOnly Property Num1 As Int32
  8.        Get
  9.            Return CInt(TextBox1.Text)
  10.        End Get
  11.    End Property
  12.  
  13.    ReadOnly Property Num2 As Int32
  14.        Get
  15.            Return CInt(TextBox2.Text)
  16.        End Get
  17.    End Property
  18.  
  19.    Private Sub Sumar(sender As Object, e As EventArgs) _
  20.    Handles Button_Sum.Click
  21.  
  22.        Dim TextBoxCount As Short = -1
  23.  
  24.        TextBoxes = {TextBox3, TextBox4, TextBox5, TextBox6}
  25.  
  26.        Result1 = {Num1 + 15, Num1 + 25} _
  27.                  .Distinct().ToArray ' Elimino duplicados
  28.  
  29.        Result2 = {Num2 + 30, Num2 + 20} _
  30.                  .Distinct().ToArray ' Elimino duplicados
  31.  
  32.        Array.Sort(Result1) : Array.Sort(Result2) ' Ordeno los Items
  33.  
  34.        For Each Number As Int32 In Result1
  35.            TextBoxCount += 1
  36.            TextBoxes(TextBoxCount).Text = Number
  37.        Next
  38.  
  39.        For Each Number As Int32 In Result2
  40.            TextBoxCount += 1
  41.            TextBoxes(TextBoxCount).Text = Number
  42.        Next
  43.  
  44.    End Sub
  45.  
  46. End Class
« Última modificación: 29 Octubre 2013, 14:46 pm por EleKtro H@cker » En línea

Que tu sabiduria no sea motivo de Humillacion para los demas
Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.788



Ver Perfil
Re: Como eliminar resultados numericos en un variable o Array ?
« Respuesta #5 en: 29 Octubre 2013, 14:52 pm »

Vamos Luis te lo he dado todo hecho, no es dificil adaptarlo, te falta poco.

En tu último código no has declarado el valor máximo
Citar
Código
  1. Dim maximum As Short = 99

Solo te falta eso y copiar esto otro:
Citar
Código
  1.        For Each Number As Integer In Result1
  2.  
  3.           TextBoxes(TextBoxCount).Text = _
  4.               If(Not Number > maximum, _
  5.                  CStr(Number), _
  6.                  CStr(maximum))
  7.  
  8.           Threading.Interlocked.Increment(TextBoxCount)
  9.  
  10.       Next Number

La verdad es que el búcle no requiere ningún cambio, pero puedes escribirlo de esta otra forma:

Código:
For Each Number As Int32 In Result1

    TextBoxCount += 1

    if not Number > maximum then
       TextBoxes(TextBoxCount).Text = cstr(number)
    else
       TextBoxes(TextBoxCount).Text = cstr(maximum)
     end if

 Next Number

Saludos
« Última modificación: 29 Octubre 2013, 14:59 pm por EleKtro H@cker » En línea

luis456


Desconectado Desconectado

Mensajes: 548



Ver Perfil
Re: Como eliminar resultados numericos en un variable o Array ?
« Respuesta #6 en: 29 Octubre 2013, 20:35 pm »

Vamos Luis te lo he dado todo hecho, no es dificil adaptarlo, te falta poco.

En tu último código no has declarado el valor máximo
Solo te falta eso y copiar esto otro:
La verdad es que el búcle no requiere ningún cambio, pero puedes escribirlo de esta otra forma:

Código:
For Each Number As Int32 In Result1

    TextBoxCount += 1

    if not Number > maximum then
       TextBoxes(TextBoxCount).Text = cstr(number)
    else
       TextBoxes(TextBoxCount).Text = cstr(maximum)
     end if

 Next Number

Saludos


Perfecto gracias EleKtro H@cker te debo una revision a tu coche :)


Luis

En línea

Que tu sabiduria no sea motivo de Humillacion para los demas
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines