De nuevo con los filtros

(1/2) > >>

luis456:
Hola

Recien resolvi o mejor dicho me resolvieron unas dudas gracias a como siempre elektro jejej ahora vengo de nuevo con algo que lo mejor es una bobera pero ya me volvi loco buscando la solucion

Explico

tengo este codigo

Código
Public Class Form1
 
   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       Dim valuesInt As IEnumerable(Of Integer) =
   {0, 1, 4, 6, 2, 8, 7}
 
       Dim pairs As IEnumerable(Of KeyValuePair(Of Integer, IEnumerable(Of Integer))) =
           From value As Integer In valuesInt
           Select New KeyValuePair(Of Integer, IEnumerable(Of Integer))(
                  key:=value,
                  value:=From index As Integer In valuesInt
                         Where index <> Integer.Parse(CStr(value).Last)
                         Select CInt(value & index))
 
       For Each pair As KeyValuePair(Of Integer, IEnumerable(Of Integer)) In pairs
 
           ListBox1.Items.Add(String.Format("Key: {0,-4} Values: {1}", pair.Key, String.Join(", ", pair.Value)))
 
       Next pair
   End Sub
End Class


lo que no puedo hacer una limitacion de los resultados o sea que si los numeros muestran del 01 al 89 y yo quiera mostrar solo desde el 01 al 50 ,no se ya que tampoco he logrado pasar estos resultados a otra variable que yo pueda o conosca manejar ya que con "pair.Key " no tengo ide de como manejar esto .


Luis








Eleкtro:
Retomando la función que te mostré aquí:
http://foro.elhacker.net/net/formar_pares_de_numeros-t442316.0.html;msg2041620#msg2041620

Le puedes añadir un parámetro opcional para limitar el valor máximo que se debe devolver.

Código
Public Class Form1
 
   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 
       Dim valuesInt As IEnumerable(Of Integer) =
           {0, 1, 4, 6, 2, 8, 7}
 
       Dim pairs As IEnumerable(Of KeyValuePair(Of Integer, IEnumerable(Of Integer))) =
           Form1.GetPairs(valuesInt, maxValue:=50)
 
       For Each pair As KeyValuePair(Of Integer, IEnumerable(Of Integer)) In pairs
 
           ListBox1.Items.Add(String.Format("Key: {0,-4} Values: {1}", pair.Key, String.Join(", ", pair.Value)))
 
       Next pair
 
   End Sub
 
   Public Shared Function GetPairs(ByVal col As IEnumerable(Of Integer),
                                   Optional ByVal maxValue As Integer = Integer.MaxValue) As IEnumerable(Of KeyValuePair(Of Integer, IEnumerable(Of Integer)))
 
       If (col.Max >= 10) Then
           Throw New ArgumentException(paramName:="col", message:="El valor máximo de la colección debe ser un valor inferior a 10.")
 
       Else
 
           Return From value As Integer In col
                  Select New KeyValuePair(Of Integer, IEnumerable(Of Integer))(
                         key:=value,
                         value:=From index As Integer In Enumerable.Range(1, 9)
                                Where (index <> value) AndAlso (CInt(value & index) <= maxValue)
                                Select CInt(value & index))
       End If
 
   End Function
 
End Class

Saludos

luis456:
Cita de: Eleкtro en  4 Octubre 2015, 14:59 pm

Retomando la función que te mostré aquí:
http://foro.elhacker.net/net/formar_pares_de_numeros-t442316.0.html;msg2041620#msg2041620

Le puedes añadir un parámetro opcional para limitar el valor máximo que se debe devolver.

Código
Public Class Form1
 
   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 
       Dim [color=yellow]valuesInt[/color] As IEnumerable(Of Integer) =
           {0, 1, 4, 6, 2, 8, 7}
 
       Dim pairs As IEnumerable(Of KeyValuePair(Of Integer, IEnumerable(Of Integer))) =
           Form1.GetPairs(valuesInt, maxValue:=50)
 
       For Each pair As KeyValuePair(Of Integer, IEnumerable(Of Integer)) In pairs
 
           ListBox1.Items.Add(String.Format("Key: {0,-4} Values: {1}", pair.Key, String.Join(", ", pair.Value)))
 
       Next pair
 
   End Sub
 
   Public Shared Function GetPairs(ByVal col As IEnumerable(Of Integer),
                                   Optional ByVal maxValue As Integer = Integer.MaxValue) As IEnumerable(Of KeyValuePair(Of Integer, IEnumerable(Of Integer)))
 
       If (col.Max >= 10) Then
           Throw New ArgumentException(paramName:="col", message:="El valor máximo de la colección debe ser un valor inferior a 10.")
 
       Else
 
           Return From value As Integer In col
                  Select New KeyValuePair(Of Integer, IEnumerable(Of Integer))(
                         key:=value,
                         value:=From index As Integer In Enumerable[color=red].Range(1, 9)[/color]
                                Where (index <> value) AndAlso (CInt(value & index) <= maxValue)
                                Select CInt(value & index))
       End If
 
   End Function
 
End Class

Saludos



Hola Elektro

No te habia respondido porque me quede dormido jejej ,bien tengo el siguiente problema con esto, ya en el anterior lo habia resuelto pero en este no se, como sabes los numeros de la variable valuesIn no mantienen la misma cantidad de numeros en cada ejecucion y estos varian. en donde esta lo de Range(1, 9) aunque en la variable haya menos numeros me toma como que si hubieran los 9 siempre


Como siempre gracias

Luis


edicto jejej creo lo resolvi pero corrigeme si estoy pelado

Código
 
           Return From value As Integer In col
                  Select New KeyValuePair(Of Integer, IEnumerable(Of Integer))(
                         key:=value,
                         value:=From index As Integer In col
                                Where (index <> value) AndAlso (CInt(value & index) <= maxValue)
                                Select CInt(value & index))













luis456:
Bueno sigo con mis enredos aunque ya esta resuelta la pregunta ahora me encuentro en otra dimension desconocida jejej se como se convierten ya las variables pero no de este tipo


codigo

Código
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 
       Dim valuesInt As IEnumerable(Of Integer) =
           {0, 1, 2, 4, 6, 7, 8}
 
       Dim pairs As IEnumerable(Of KeyValuePair(Of Integer, IEnumerable(Of Integer))) =
           Form1.GetPairs(valuesInt, maxValue:=80)
 
       For Each pair As KeyValuePair(Of Integer, IEnumerable(Of Integer)) In pairs
 
           ListBox1.Items.Add(String.Format("Key: {0,-4} Values: {1}", pair.Key, String.Join(", ", pair.Value)))
 
       Next pair
 
   End Sub
 
   Public Shared Function GetPairs(ByVal col As IEnumerable(Of Integer),
                                   Optional ByVal maxValue As Integer = Integer.MaxValue) As IEnumerable(Of KeyValuePair(Of Integer, IEnumerable(Of Integer)))
 
       If (col.Max >= 10) Then
           Throw New ArgumentException(paramName:="col", message:="El valor máximo de la colección debe ser un valor inferior a 10.")
 
       Else
 
           Return From value As Integer In col
                  Select New KeyValuePair(Of Integer, IEnumerable(Of Integer))(
                         key:=value,
                         value:=From index As Integer In Enumerable.Range(1, 9)
                                Where (index <> value) AndAlso (CInt(value & index) <= maxValue)
                                Select CInt(value & index))
       End If
 
   End Function
 
End Class


esto entrega estos resultados y quiero pasarlos a unas variables normalitas jejje

Key: 0    Values: 1, 2, 4, 5, 6, 7, 8
Key: 1    Values: 10, 12, 14, 15, 16, 17, 18
Key: 2    Values: 20, 21, 24, 25, 26, 27, 28
Key: 4    Values: 40, 41, 42, 45, 46, 47, 48
Key: 5    Values: 50, 51, 52, 54, 56, 57, 58
Key: 6    Values: 60, 61, 62, 64, 65, 67, 68
Key: 7    Values: 70, 71, 72, 74, 75, 76, 78
Key: 8    Values: 80, 81, 82, 84, 85, 86, 87


 como puedo meter en cada variable los valores de cada key
ejemplo
variable 0 = 1, 2, 4, 5, 6, 7, 8
variable 1= 10, 12, 14, 15, 16, 17, 18
variable 2= 20, 21, 24, 25, 26, 27, 28


Luis








Eleкtro:
Lo tienes perfecto tal y como está, es más productivo así.

Creo que solo necesitas un ejemplo de cómo usar el índice (no deberías necesitar un ejemplo a estas alturasss), como el siguiente, por que yo no le veo ninguna dificultad de accesibilidad adicional entre hacer esto:
Código
' Dim pairs As IEnumerable(Of KeyValuePair(Of Integer, IEnumerable(Of Integer))) = ...
MsgBox(String.Join(", ", pairs(0).Value))

...o hacer esto otro:
Código
' Dim col As IEnumerable(Of IEnumerable(Of Integer)) = ...
MsgBox(String.Join(", ", col(0)))

Para hacer lo segundo, cosa que repito ...es innecesario, pero bueno, tendrías que modificar el tipo de objeto que maneja la función, para devolver un IEnumerable(Of IEnumerable(Of Integer)) claro está...

Saludos!

Navegación

[0] Índice de Mensajes

[#] Página Siguiente