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

 

 


Tema destacado: Entrar al Canal Oficial Telegram de elhacker.net


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP) (Moderador: kub0x)
| | | |-+  Pregunta Boba / como pasar registros desde un listbox a variables
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: 1 [2] Ir Abajo Respuesta Imprimir
Autor Tema: Pregunta Boba / como pasar registros desde un listbox a variables  (Leído 8,293 veces)
luis456


Desconectado Desconectado

Mensajes: 548



Ver Perfil
Re: Pregunta Boba / como pasar registros desde un listbox a variables
« Respuesta #10 en: 7 Abril 2016, 14:26 pm »

Pero no sería pasarlo a integer, sino crear una colección o matriz interpretando cada elemento de una cadena de texto distinto de " " como integer. De ahí el uso que le das de Split


Al parecer tiene dos códigos, uno que le pasé yo y otro el tuyo Elektro. El cual estará como lo acabas de poner. Y quiere usar los dos en el mismo proyecto

Eso mismo  es lo que quiero ya que si no tendria que modificar todo lo que llevo en años  :silbar:


En línea

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

Desconectado Desconectado

Mensajes: 268



Ver Perfil
Re: Pregunta Boba / como pasar registros desde un listbox a variables
« Respuesta #11 en: 7 Abril 2016, 15:42 pm »

Lo que no entiendo es por qué no usas este otro código que te pasó Elektro y que modifiqué para 6 números y para que no hubieran correlativos.

Todas las combinaciones:

Código
  1.        Dim intCol As New List(Of Integer)({1, 2, 3, 4, 5, 6, 7, 8, 9, 10}.OfType(Of Integer))
  2.  
  3.        Dim pairsCol As IEnumerable(Of String) = Nothing
  4.  
  5.        pairsCol =
  6.            From value1 As Integer In intCol
  7.            From value2 As Integer In intCol
  8.            From value3 As Integer In intCol
  9.            From value4 As Integer In intCol
  10.            From value5 As Integer In intCol
  11.            Select String.Join(Environment.NewLine, (
  12.                               From value6 As Integer In intCol
  13.                                  Where (value1 <> value2) AndAlso
  14.                                        (value1 <> value3) AndAlso
  15.                                        (value1 <> value4) AndAlso
  16.                                        (value1 <> value5) AndAlso
  17.                                        (value1 <> value6) AndAlso
  18.                                        (value2 <> value3) AndAlso
  19.                                        (value2 <> value4) AndAlso
  20.                                        (value2 <> value5) AndAlso
  21.                                        (value2 <> value6) AndAlso
  22.                                        (value3 <> value4) AndAlso
  23.                                        (value3 <> value5) AndAlso
  24.                                        (value3 <> value6) AndAlso
  25.                                        (value4 <> value5) AndAlso
  26.                                        (value4 <> value6) AndAlso
  27.                                        (value5 <> value6) AndAlso
  28.                                        (value2 > value1) AndAlso
  29.                                        (value3 > value2) AndAlso
  30.                                        (value4 > value3) AndAlso
  31.                                        (value5 > value4) AndAlso
  32.                                        (value6 > value5)
  33.                                  Select String.Format("{0:00} {1:00} {2:00} {3:00} {4:00} {5:00}",
  34.                                                       value1, value2, value3, value4, value5, value6)))
  35.  
  36.  
  37.        For Each pairs As String In pairsCol
  38.            For Each line As String In pairs.Split({Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)
  39.                ListBox1.Items.Add(line)
  40.            Next line
  41.  
  42.        Next pairs
  43.  
  44.  



Combinaciones SIN todos los  números correlativos

Código
  1.      Dim intCol As New List(Of Integer)({1, 2, 3, 4, 5, 6, 7, 8, 9, 10}.OfType(Of Integer))
  2.  
  3.        Dim pairsCol As IEnumerable(Of String) = Nothing
  4.  
  5.        pairsCol =
  6. From value1 As Integer In intCol
  7. From value2 As Integer In intCol
  8. From value3 As Integer In intCol
  9. From value4 As Integer In intCol
  10. From value5 As Integer In intCol
  11. Select String.Join(Environment.NewLine, (
  12.              From value6 As Integer In intCol
  13.                 Where (value1 <> value2) AndAlso
  14.                       (value1 <> value3) AndAlso
  15.                       (value1 <> value4) AndAlso
  16.                       (value1 <> value5) AndAlso
  17.                       (value1 <> value6) AndAlso
  18.                       (value2 <> value3) AndAlso
  19.                       (value2 <> value4) AndAlso
  20.                       (value2 <> value5) AndAlso
  21.                       (value2 <> value6) AndAlso
  22.                       (value3 <> value4) AndAlso
  23.                       (value3 <> value5) AndAlso
  24.                       (value3 <> value6) AndAlso
  25.                       (value4 <> value5) AndAlso
  26.                       (value4 <> value6) AndAlso
  27.                       (value5 <> value6) AndAlso
  28.                       (value2 > value1) AndAlso
  29.                       (value3 > value2) AndAlso
  30.                       (value4 > value3) AndAlso
  31.                       (value5 > value4) AndAlso
  32.                       (value6 > value5)
  33.                 Select String.Format("{0:00} {1:00} {2:00} {3:00} {4:00} {5:00}",
  34.                                      value1, value2, value3, value4, value5, value6)))
  35.  
  36.  
  37.        For Each pairs As String In pairsCol
  38.            For Each line As String In pairs.Split({Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)
  39.                Dim Pattern As String = " "
  40.                Dim Digito() As String
  41.                Digito = System.Text.RegularExpressions.Regex.Split(line, Pattern)
  42.  
  43.                        If CInt(Digito(1)) <> CInt(Digito(0)) + 1 Or
  44.                                CInt(Digito(2)) <> CInt(Digito(1)) + 1 Or
  45.                                    CInt(Digito(3)) <> CInt(Digito(2)) + 1 Or
  46.                                     CInt(Digito(4)) <> CInt(Digito(3)) + 1 Or
  47.                                       CInt(Digito(5)) <> CInt(Digito(4)) + 1 Then
  48.                    ListBox1.Items.Add(line)
  49.  
  50.                End If
  51.            Next line
  52.  
  53.        Next pairs



Pero no me queda claro como pasar cada Item a Integer.

Este ejemplo, al final va obteniendo los números y crea una array cuyos items son los números de una combinación pero no se como se podría crear otro array con cada array ?¿?¿?¿

Código
  1.        Dim intCol As New List(Of Integer)({1, 2, 3, 4, 5, 6, 7, 8, 9, 10}.OfType(Of Integer))
  2.  
  3.        Dim pairsCol As IEnumerable(Of String) = Nothing
  4.  
  5.        pairsCol =
  6. From value1 As Integer In intCol
  7. From value2 As Integer In intCol
  8. From value3 As Integer In intCol
  9. From value4 As Integer In intCol
  10. From value5 As Integer In intCol
  11. Select String.Join(Environment.NewLine, (
  12.              From value6 As Integer In intCol
  13.                 Where (value1 <> value2) AndAlso
  14.                       (value1 <> value3) AndAlso
  15.                       (value1 <> value4) AndAlso
  16.                       (value1 <> value5) AndAlso
  17.                       (value1 <> value6) AndAlso
  18.                       (value2 <> value3) AndAlso
  19.                       (value2 <> value4) AndAlso
  20.                       (value2 <> value5) AndAlso
  21.                       (value2 <> value6) AndAlso
  22.                       (value3 <> value4) AndAlso
  23.                       (value3 <> value5) AndAlso
  24.                       (value3 <> value6) AndAlso
  25.                       (value4 <> value5) AndAlso
  26.                       (value4 <> value6) AndAlso
  27.                       (value5 <> value6) AndAlso
  28.                       (value2 > value1) AndAlso
  29.                       (value3 > value2) AndAlso
  30.                       (value4 > value3) AndAlso
  31.                       (value5 > value4) AndAlso
  32.                       (value6 > value5)
  33.                 Select String.Format("{0:00} {1:00} {2:00} {3:00} {4:00} {5:00}",
  34.                                      value1, value2, value3, value4, value5, value6)))
  35.  
  36.  
  37.        For Each pairs As String In pairsCol
  38.            For Each line As String In pairs.Split({Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)
  39.                Dim Pattern As String = " "
  40.                Dim Digito() As String
  41.                Digito = System.Text.RegularExpressions.Regex.Split(line, Pattern)
  42.  
  43.                        If CInt(Digito(1)) <> CInt(Digito(0)) + 1 Or
  44.                                CInt(Digito(2)) <> CInt(Digito(1)) + 1 Or
  45.                                    CInt(Digito(3)) <> CInt(Digito(2)) + 1 Or
  46.                                     CInt(Digito(4)) <> CInt(Digito(3)) + 1 Or
  47.                                       CInt(Digito(5)) <> CInt(Digito(4)) + 1 Then
  48.                    ListBox1.Items.Add(line)
  49.  
  50.                End If
  51.            Next line
  52.  
  53.        Next pairs
  54.  
  55.        '//Esto solo crea un array con la última combinación.
  56.       '//En realidad lo hace con todas pero solo queda registrada la última
  57.       '//¿Habría que hacer una colección de arrays?
  58.        Dim NuevaLista As New List(Of String)(ListBox1.Items.OfType(Of String))
  59.        Dim int32Col As IEnumerable(Of Integer) = Nothing
  60.  
  61.        For Each item As String In NuevaLista
  62.            int32Col = From Elemento As String In item.Split(" "c) Select CInt(Elemento)
  63.        Next
  64.  
  65.        'Los números de la última combinación
  66.        MessageBox.Show(int32Col(0).ToString)
  67.        MessageBox.Show(int32Col(1).ToString)
  68.        MessageBox.Show(int32Col(2).ToString)
  69.        MessageBox.Show(int32Col(3).ToString)
  70.        MessageBox.Show(int32Col(4).ToString)
  71.        MessageBox.Show(int32Col(5).ToString)
  72.  


FALTABA UN:

Código:
(value5 <> value6) AndAlso

Ya lo he puesto  :¬¬


« Última modificación: 7 Abril 2016, 16:42 pm por Lekim » En línea

luis456


Desconectado Desconectado

Mensajes: 548



Ver Perfil
Re: Pregunta Boba / como pasar registros desde un listbox a variables
« Respuesta #12 en: 7 Abril 2016, 16:55 pm »

Lo que no entiendo es por qué no usas este otro código que te pasó Elektro y que modifiqué para 6 números y para que no hubieran correlativos.

Todas las combinaciones:

Código
  1.        Dim intCol As New List(Of Integer)({1, 2, 3, 4, 5, 6, 7, 8, 9, 10}.OfType(Of Integer))
  2.  
  3.        Dim pairsCol As IEnumerable(Of String) = Nothing
  4.  
  5.        pairsCol =
  6.            From value1 As Integer In intCol
  7.            From value2 As Integer In intCol
  8.            From value3 As Integer In intCol
  9.            From value4 As Integer In intCol
  10.            From value5 As Integer In intCol
  11.            Select String.Join(Environment.NewLine, (
  12.                               From value6 As Integer In intCol
  13.                                  Where (value1 <> value2) AndAlso
  14.                                        (value1 <> value3) AndAlso
  15.                                        (value1 <> value4) AndAlso
  16.                                        (value1 <> value5) AndAlso
  17.                                        (value1 <> value6) AndAlso
  18.                                        (value2 <> value3) AndAlso
  19.                                        (value2 <> value4) AndAlso
  20.                                        (value2 <> value5) AndAlso
  21.                                        (value2 <> value6) AndAlso
  22.                                        (value3 <> value4) AndAlso
  23.                                        (value3 <> value5) AndAlso
  24.                                        (value3 <> value6) AndAlso
  25.                                        (value4 <> value5) AndAlso
  26.                                        (value4 <> value6) AndAlso
  27.                                        (value5 <> value6) AndAlso
  28.                                        (value2 > value1) AndAlso
  29.                                        (value3 > value2) AndAlso
  30.                                        (value4 > value3) AndAlso
  31.                                        (value5 > value4) AndAlso
  32.                                        (value6 > value5)
  33.                                  Select String.Format("{0:00} {1:00} {2:00} {3:00} {4:00} {5:00}",
  34.                                                       value1, value2, value3, value4, value5, value6)))
  35.  
  36.  
  37.        For Each pairs As String In pairsCol
  38.            For Each line As String In pairs.Split({Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)
  39.                ListBox1.Items.Add(line)
  40.            Next line
  41.  
  42.        Next pairs
  43.  
  44.  



Combinaciones SIN todos los  números correlativos

Código
  1.      Dim intCol As New List(Of Integer)({1, 2, 3, 4, 5, 6, 7, 8, 9, 10}.OfType(Of Integer))
  2.  
  3.        Dim pairsCol As IEnumerable(Of String) = Nothing
  4.  
  5.        pairsCol =
  6. From value1 As Integer In intCol
  7. From value2 As Integer In intCol
  8. From value3 As Integer In intCol
  9. From value4 As Integer In intCol
  10. From value5 As Integer In intCol
  11. Select String.Join(Environment.NewLine, (
  12.              From value6 As Integer In intCol
  13.                 Where (value1 <> value2) AndAlso
  14.                       (value1 <> value3) AndAlso
  15.                       (value1 <> value4) AndAlso
  16.                       (value1 <> value5) AndAlso
  17.                       (value1 <> value6) AndAlso
  18.                       (value2 <> value3) AndAlso
  19.                       (value2 <> value4) AndAlso
  20.                       (value2 <> value5) AndAlso
  21.                       (value2 <> value6) AndAlso
  22.                       (value3 <> value4) AndAlso
  23.                       (value3 <> value5) AndAlso
  24.                       (value3 <> value6) AndAlso
  25.                       (value4 <> value5) AndAlso
  26.                       (value4 <> value6) AndAlso
  27.                       (value5 <> value6) AndAlso
  28.                       (value2 > value1) AndAlso
  29.                       (value3 > value2) AndAlso
  30.                       (value4 > value3) AndAlso
  31.                       (value5 > value4) AndAlso
  32.                       (value6 > value5)
  33.                 Select String.Format("{0:00} {1:00} {2:00} {3:00} {4:00} {5:00}",
  34.                                      value1, value2, value3, value4, value5, value6)))
  35.  
  36.  
  37.        For Each pairs As String In pairsCol
  38.            For Each line As String In pairs.Split({Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)
  39.                Dim Pattern As String = " "
  40.                Dim Digito() As String
  41.                Digito = System.Text.RegularExpressions.Regex.Split(line, Pattern)
  42.  
  43.                        If CInt(Digito(1)) <> CInt(Digito(0)) + 1 Or
  44.                                CInt(Digito(2)) <> CInt(Digito(1)) + 1 Or
  45.                                    CInt(Digito(3)) <> CInt(Digito(2)) + 1 Or
  46.                                     CInt(Digito(4)) <> CInt(Digito(3)) + 1 Or
  47.                                       CInt(Digito(5)) <> CInt(Digito(4)) + 1 Then
  48.                    ListBox1.Items.Add(line)
  49.  
  50.                End If
  51.            Next line
  52.  
  53.        Next pairs



Pero no me queda claro como pasar cada Item a Integer.

Este ejemplo, al final va obteniendo los números y crea una array cuyos items son los números de una combinación pero no se como se podría crear otro array con cada array ?¿?¿?¿

Código
  1.        Dim intCol As New List(Of Integer)({1, 2, 3, 4, 5, 6, 7, 8, 9, 10}.OfType(Of Integer))
  2.  
  3.        Dim pairsCol As IEnumerable(Of String) = Nothing
  4.  
  5.        pairsCol =
  6. From value1 As Integer In intCol
  7. From value2 As Integer In intCol
  8. From value3 As Integer In intCol
  9. From value4 As Integer In intCol
  10. From value5 As Integer In intCol
  11. Select String.Join(Environment.NewLine, (
  12.              From value6 As Integer In intCol
  13.                 Where (value1 <> value2) AndAlso
  14.                       (value1 <> value3) AndAlso
  15.                       (value1 <> value4) AndAlso
  16.                       (value1 <> value5) AndAlso
  17.                       (value1 <> value6) AndAlso
  18.                       (value2 <> value3) AndAlso
  19.                       (value2 <> value4) AndAlso
  20.                       (value2 <> value5) AndAlso
  21.                       (value2 <> value6) AndAlso
  22.                       (value3 <> value4) AndAlso
  23.                       (value3 <> value5) AndAlso
  24.                       (value3 <> value6) AndAlso
  25.                       (value4 <> value5) AndAlso
  26.                       (value4 <> value6) AndAlso
  27.                       (value5 <> value6) AndAlso
  28.                       (value2 > value1) AndAlso
  29.                       (value3 > value2) AndAlso
  30.                       (value4 > value3) AndAlso
  31.                       (value5 > value4) AndAlso
  32.                       (value6 > value5)
  33.                 Select String.Format("{0:00} {1:00} {2:00} {3:00} {4:00} {5:00}",
  34.                                      value1, value2, value3, value4, value5, value6)))
  35.  
  36.  
  37.        For Each pairs As String In pairsCol
  38.            For Each line As String In pairs.Split({Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)
  39.                Dim Pattern As String = " "
  40.                Dim Digito() As String
  41.                Digito = System.Text.RegularExpressions.Regex.Split(line, Pattern)
  42.  
  43.                        If CInt(Digito(1)) <> CInt(Digito(0)) + 1 Or
  44.                                CInt(Digito(2)) <> CInt(Digito(1)) + 1 Or
  45.                                    CInt(Digito(3)) <> CInt(Digito(2)) + 1 Or
  46.                                     CInt(Digito(4)) <> CInt(Digito(3)) + 1 Or
  47.                                       CInt(Digito(5)) <> CInt(Digito(4)) + 1 Then
  48.                    ListBox1.Items.Add(line)
  49.  
  50.                End If
  51.            Next line
  52.  
  53.        Next pairs
  54.  
  55.        '//Esto solo crea un array con la última combinación.
  56.       '//En realidad lo hace con todas pero solo queda registrada la última
  57.       '//¿Habría que hacer una colección de arrays?
  58.        Dim NuevaLista As New List(Of String)(ListBox1.Items.OfType(Of String))
  59.        Dim int32Col As IEnumerable(Of Integer) = Nothing
  60.  
  61.        For Each item As String In NuevaLista
  62.            int32Col = From Elemento As String In item.Split(" "c) Select CInt(Elemento)
  63.        Next
  64.  
  65.        'Los números de la última combinación
  66.        MessageBox.Show(int32Col(0).ToString)
  67.        MessageBox.Show(int32Col(1).ToString)
  68.        MessageBox.Show(int32Col(2).ToString)
  69.        MessageBox.Show(int32Col(3).ToString)
  70.        MessageBox.Show(int32Col(4).ToString)
  71.        MessageBox.Show(int32Col(5).ToString)
  72.  


FALTABA UN:

Código:
(value5 <> value6) AndAlso

Ya lo he puesto  :¬¬



Ya te agradezco la ayuda pero esto ya lo tengo cubierto, tengo mas filtros de lo que seguro usare jejej cuando tienes una idea pero no sabes como implementarlo es lo Jo,,,

Lo que pasa y como sabe  "El padre de Net "   jejej (elektro es broma ) casi todo mi programa esta hecho en linq: por eso cuando me salgo de la linea esa me pierdo  :silbar: :silbar:
pero como soy terco jejej no creo que no se pueda convertir los datos de un listbox en una simple variable


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: Pregunta Boba / como pasar registros desde un listbox a variables
« Respuesta #13 en: 7 Abril 2016, 17:03 pm »

no creo que no se pueda convertir los datos de un listbox en una simple variable

Asumo que por variable te estás refiriendo a un Array de enteros, ¿has leido mi última respuesta en este hilo?, ahí te expliqué como hacerlo, y de varias maneras...

Si no es eso lo que quieres hacer entonces yo no me estoy enterando (para variar...)

Saludos
« Última modificación: 7 Abril 2016, 17:13 pm por Eleкtro » En línea

luis456


Desconectado Desconectado

Mensajes: 548



Ver Perfil
Re: Pregunta Boba / como pasar registros desde un listbox a variables
« Respuesta #14 en: 7 Abril 2016, 18:07 pm »

Asumo que por variable te estás refiriendo a un Array de enteros, ¿has leido mi última respuesta en este hilo?, ahí te expliqué como hacerlo, y de varias maneras...

Si no es eso lo que quieres hacer entonces yo no me estoy enterando (para variar...)

Saludos

Que si hombre lo que paso es que solo vi lo de Lekim ,tenia un ojo en el visual y otro aca no lo vi bien jeje como siempre gracias Elektro

Clausurado este post jejje hasta la siguiente pregunta  :silbar: :silbar: :silbar:


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: Pregunta Boba / como pasar registros desde un listbox a variables
« Respuesta #15 en: 7 Abril 2016, 18:54 pm »

Que si hombre lo que paso es que solo vi lo de Lekim ,tenia un ojo en el visual y otro aca no lo vi bien jeje como siempre gracias Elektro

Clausurado este post jejje hasta la siguiente pregunta  :silbar: :silbar: :silbar:


Luis

Te lo pregunto más que nada por que yo no me voy a seguir conectando con la misma frecuencia al foro por motivos...indeseables, por si necesitas (mi) ayuda AHORA. ¿seguro que se ha resuelto tu duda?, de lo contrario dilo sin miedo, que no como xd

saludos
En línea

luis456


Desconectado Desconectado

Mensajes: 548



Ver Perfil
Re: Pregunta Boba / como pasar registros desde un listbox a variables
« Respuesta #16 en: 7 Abril 2016, 19:12 pm »

Te lo pregunto más que nada por que yo no me voy a seguir conectando con la misma frecuencia al foro por motivos...indeseables, por si necesitas (mi) ayuda AHORA. ¿seguro que se ha resuelto tu duda?, de lo contrario dilo sin miedo, que no como xd

saludos

No de verdad esta listo , solo te pido que me dejes un email en mi privado  :silbar: :silbar: :silbar:

Luis
En línea

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

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Pregunta boba de Vb
Programación Visual Basic
GrTk 6 2,014 Último mensaje 22 Julio 2006, 13:28 pm
por Hans el Topo
como recorrer Listbox y pasar valores a un arreglo?
Programación Visual Basic
GhostLT 4 18,215 Último mensaje 26 Mayo 2016, 16:27 pm
por SirioCasius
Pasar listbox a textbox al hacer click en un valor del listbox
.NET (C#, VB.NET, ASP)
BrokerJoker 3 23,449 Último mensaje 13 Mayo 2012, 17:13 pm
por BrokerJoker
pregunta boba, siglas de archivos
Dudas Generales
basickdagger 3 2,358 Último mensaje 5 Junio 2014, 17:00 pm
por basickdagger
Seguimos con registros en listbox :)
.NET (C#, VB.NET, ASP)
luis456 8 3,825 Último mensaje 29 Marzo 2016, 14:23 pm
por Lekim
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines