|
381
|
Programación / .NET (C#, VB.NET, ASP) / Re: Como puedo saber los números que faltan dentro del rango ?
|
en: 28 Enero 2014, 11:43 am
|
ahora si funciona Public Class Form1 Dim Max As Integer = 99 Dim Xmin As Integer = 0 Dim x As Integer = 0 Dim Número As Double Private TextBoxes As TextBox() = {Nothing} Private Result1 As Int32(), Result2 As Int32(), Result3 As Int32() Private _textBox As Object Private _getNumbersNotInRange As Object Private Property ListBox1Count As Integer Private Property Calcular As Object Private Property TextBox(ByVal TextBoxCount As Short) As Object Get Return _textBox End Get Set(ByVal value As Object) _textBox = value End Set End Property ReadOnly Property Num1 As Int32 Get Return CInt(TextBox1.Text) End Get End Property ReadOnly Property Num2 As Int32 Get Return CInt(TextBox2.Text) End Get End Property ReadOnly Property Num3 As Int32 Get Return CInt(TextBox3.Text) End Get End Property Private Property GetNumbersNotInRange(ByVal Result11 As IEnumerable(Of Integer), ByVal Xmin As Integer, ByVal XMax As Integer) As Object Get Return _getNumbersNotInRange End Get Set(ByVal value As Object) _getNumbersNotInRange = value End Set End Property Private Sub Sumar(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click Result1 = {Num1 + 10, Num1 + 20, Num1 + 30} _ .Distinct().ToArray ' Elimino duplicados Result2 = {Num2 + 10, Num2 + 20, Num2 + 30} _ .Distinct().ToArray ' Elimino duplicados Result3 = {Num3 + 10, Num3 + 20, Num3 + 30} _ .Distinct().ToArray ' Elimino duplicados ' primero concatenas y eliminas duplicados en el primer array: Dim Result11 As IEnumerable(Of Integer) = (Result1.Concat(Result2).Concat(Result3). Distinct) ' Dim arregloSumas() As Integer = {10, 15, 20, 25, 30} Dim numerosFaltantesdelRango() As Integer = {} Dim rango_min As Integer = 0, rango_max As Integer = 99 Dim tamanio As Integer Dim val As Integer Dim test As Integer For i = rango_min To rango_max val = i If Array.Exists(Result11.Cast(Of Object).ToArray, Function(value As Integer) value = val) = False Then 'Compruebo si el valor de i no aparece en el arreglo de las sumas test += 1 tamanio = UBound(numerosFaltantesdelRango) + 1 ReDim Preserve numerosFaltantesdelRango(tamanio) numerosFaltantesdelRango(tamanio) = val 'Agrego el valor al arreglo End If Next ListBox1.Items.AddRange(numerosFaltantesdelRango.Cast(Of Object).ToArray) End Sub End Class
Perfecto perfecto Funciona como quería ¡ muchas gracias por tu ayuda Luis
|
|
|
382
|
Programación / .NET (C#, VB.NET, ASP) / Re: Como puedo saber los números que faltan dentro del rango ?
|
en: 26 Enero 2014, 18:40 pm
|
en la respuesta que puse te deje un algoritmo sencillo de como hacer eso, y funciona
Como ya comente en esto soy novato lo mio era el viejo foxpro jejej pongo el codigo pero me error Public Class Form1 Dim Max As Integer = 99 Dim Xmin As Integer = 0 Dim x As Integer = 0 Dim Número As Double Private TextBoxes As TextBox() = {Nothing} Private Result1 As Int32(), Result2 As Int32(), Result3 As Int32() Private _textBox As Object Private _getNumbersNotInRange As Object Private Property ListBox1Count As Integer Private Property Calcular As Object Private Property TextBox(ByVal TextBoxCount As Short) As Object Get Return _textBox End Get Set(ByVal value As Object) _textBox = value End Set End Property ReadOnly Property Num1 As Int32 Get Return CInt(TextBox1.Text) End Get End Property ReadOnly Property Num2 As Int32 Get Return CInt(TextBox2.Text) End Get End Property ReadOnly Property Num3 As Int32 Get Return CInt(TextBox3.Text) End Get End Property Private Property GetNumbersNotInRange(ByVal Result11 As IEnumerable(Of Integer), ByVal Xmin As Integer, ByVal XMax As Integer) As Object Get Return _getNumbersNotInRange End Get Set(ByVal value As Object) _getNumbersNotInRange = value End Set End Property Private Sub Sumar(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click Result1 = {Num1 + 10, Num1 + 20, Num1 + 30} _ .Distinct().ToArray ' Elimino duplicados Result2 = {Num2 + 10, Num2 + 20, Num2 + 30} _ .Distinct().ToArray ' Elimino duplicados Result3 = {Num3 + 10, Num3 + 20, Num3 + 30} _ .Distinct().ToArray ' Elimino duplicados ' primero concatenas y eliminas duplicados en el primer array: Dim Result11 As IEnumerable(Of Integer) = (Result1.Concat(Result2).Concat(Result3). Distinct) ' Dim arregloSumas() As Integer = {10, 15, 20, 25, 30} Dim numerosFaltantesdelRango() As Integer = {} Dim rango_min As Integer = 0, rango_max As Integer = 99 Dim tamanio As Integer Dim val As Integer For i = rango_min To rango_max val = i If Array.Exists(Result11, Function(value As Integer) value = val) = False Then 'Compruebo si el valor de i no aparece en el arreglo de las sumas tamanio = numerosFaltantesdelRango.Length + 1 ReDim numerosFaltantesdelRango(tamanio) numerosFaltantesdelRango(tamanio) = val 'Agrego el valor al arreglo End If Next ListBox1.Items.AddRange(numerosFaltantesdelRango.Cast(Of Object).ToArray) End Sub End Class
|
|
|
384
|
Programación / .NET (C#, VB.NET, ASP) / Re: Como puedo saber los números que faltan dentro del rango ?
|
en: 22 Enero 2014, 17:43 pm
|
A simple vista, no hay nada erroneo en la instrucción. comprueba si la linea que me has mostrado es la misma que hace referencia a esta: Comprueba que todos los valores que usas en el método de LINQ seán Integers, no longs no shorts no otra cosa, y prueba así, sin especificar el datatype de retorno: Result11 = Result11.Select(Function(Value) If(Value < MAX, Value, Rand.Next(0, MAX)))
De todas formas aún sigo esperando a que des un maldito detalle sobre el tipo de excepción de la que se trata, si en tiempo de ejecución o un error de compilación, aunque está claro que es de compilación pero bueno... para la próxima vez. PD: Siempre puedes ponerle un par de breakpoints para inspeccionar más detalládamente los sucesos si se trata de una excepción en tiempo de ejecución. saludos si elektro hace referencia a Form1.vb 78 Y el error es en tiempo de compilación Luis
|
|
|
385
|
Programación / .NET (C#, VB.NET, ASP) / Re: Como puedo saber los números que faltan dentro del rango ?
|
en: 22 Enero 2014, 17:14 pm
|
Hola esto es lo que puedo copiar,me remarca todo el codigo que me diste Result11 = Result11.Select(Function(Value As Integer) If(Value < MAX, Value, Rand.Next(0, MAX))) Error 2 Error de resolución de sobrecarga porque ninguna de las funciones 'Select' a las que se tiene acceso se puede llamar con estos argumentos: Método de extensión 'Public Function Select(Of TResult)(selector As System.Func(Of Integer, Integer, TResult)) As System.Collections.Generic.IEnumerable(Of TResult)' definido en 'System.Linq.Enumerable': La función anidada no tiene una firma compatible con el delegado 'System.Func(Of Integer, Integer, TResult)'. Método de extensión 'Public Function Select(Of TResult)(selector As System.Func(Of Integer, Integer, TResult)) As System.Collections.Generic.IEnumerable(Of TResult)' definido en 'System.Linq.Enumerable': Los tipos de datos de los parámetros de tipo no se pueden inferir de estos argumentos. Este error se puede resolver especificando los tipos de datos explícitamente. Método de extensión 'Public Function Select(Of TResult)(selector As System.Func(Of Integer, TResult)) As System.Collections.Generic.IEnumerable(Of TResult)' definido en 'System.Linq.Enumerable': 'Rand' no está declarado. Puede que esté inaccesible debido a su nivel de protección. Método de extensión 'Public Function Select(Of TResult)(selector As System.Func(Of Integer, TResult)) As System.Collections.Generic.IEnumerable(Of TResult)' definido en 'System.Linq.Enumerable': Los tipos de datos de los parámetros de tipo no se pueden inferir de estos argumentos. Este error se puede resolver especificando los tipos de datos explícitamente. C:\Users\Acuario\documents\visual studio 2010\Projects\Preueba\Preueba\Form1.vb 78 20 Preueba
Luis
|
|
|
386
|
Programación / .NET (C#, VB.NET, ASP) / Re: Como puedo saber los números que faltan dentro del rango ?
|
en: 22 Enero 2014, 15:04 pm
|
seguimos error de resolucion de sobre carga pongo codigo entero Public Class Form1
Dim XMax As Short = 99 Dim Xmin As Short = 0 Dim x As Integer = 0 Dim Número As Double Private TextBoxes As TextBox() = {Nothing} Private Result1 As Int32(), Result2 As Int32(), Result3 As Int32() Private _textBox As Object Private _getNumbersNotInRange As Object
Private Property ListBox1Count As Integer ReadOnly MAX As Integer = 99 Private Property Calcular As Object
Private Property TextBox(ByVal TextBoxCount As Short) As Object Get Return _textBox End Get Set(ByVal value As Object) _textBox = value End Set End Property
ReadOnly Property Num1 As Int32 Get Return CInt(TextBox1.Text) End Get End Property
ReadOnly Property Num2 As Int32 Get Return CInt(TextBox2.Text) End Get End Property ReadOnly Property Num3 As Int32 Get Return CInt(TextBox3.Text) End Get End Property
Private Property GetNumbersNotInRange(ByVal Result11 As IEnumerable(Of Integer), ByVal Xmin As Integer, ByVal XMax As Integer) As Object Get Return _getNumbersNotInRange End Get Set(ByVal value As Object) _getNumbersNotInRange = value End Set End Property
Private Sub Sumar(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Result1 = {Num1 + 10, Num1 + 20, Num1 + 30} _ .Distinct().ToArray ' Elimino duplicados
Result2 = {Num2 + 10, Num2 + 20, Num2 + 30} _ .Distinct().ToArray ' Elimino duplicados
Result3 = {Num3 + 10, Num3 + 20, Num3 + 30} _ .Distinct().ToArray ' Elimino duplicados
' primero concatenas y eliminas duplicados en el primer array: Dim Result11 As IEnumerable(Of Integer) = (Result1.Concat(Result2).Concat(Result3). Distinct)
' luego instancias un segundo array que obtiene los números que no están dentro del rango 'Xmin'-'Xmax' del primer array: Dim NumbersNotInRange As Integer() = GetNumbersNotInRange(Result11, Xmin, XMax).ToArray
' Y por último reemplazas los números que no están en el rango, en el primer array: Result11 = Result11.Select(Function(Value As Integer) If(Value < MAX, Value, Rand.Next(0, MAX))) <----------------------aca
' y los añades a los listbox: ListBox1.Items.AddRange(Result11.Cast(Of Object).ToArray) ListBox2.Items.AddRange(NumbersNotInRange.Cast(Of Object).ToArray)
End Sub End Class Luis
|
|
|
387
|
Programación / .NET (C#, VB.NET, ASP) / Re: Como puedo saber los números que faltan dentro del rango ?
|
en: 22 Enero 2014, 14:46 pm
|
El código de arriba lo escribí al vuelo, no me di cuenta de un fallo muy grande, en lugar de un Return le puse ReadOnly xD, déjalo asi: Result11 = Result11.Select(Function(Value As Integer) If(Value < MAX, Value, Rand.Next(0, MAX)))
Y por cierto, esto tal vez quieras revisarlo...: (concatenas dos veces Result3). Saludos Si elektro lo pille tarde cuando puse el post las putas prisas y la presbicia de mis ojos me juegan malas pasadas jejej.ahora pruebo de nuevo a ver Gracias Luis
|
|
|
388
|
Programación / .NET (C#, VB.NET, ASP) / Re: Como puedo saber los números que faltan dentro del rango ?
|
en: 22 Enero 2014, 10:31 am
|
Porfavor, detalles!.
1. Que significa "no funciona", ¿te salta alguna excepción?.
2. Número de linea exacta en el que te salta la excepción junto al mensaje de error y el stacktrace.
saludos!
Me salta esto " error de sobrecarga porque ninguna seleccion selet se puede llamar a las que se tiene acceso se puede llamar con estos argumentos " ' primero concatenas y eliminas duplicados en el primer array: Dim Result11 As IEnumerable(Of Integer) = (Result1.Concat(Result3).Concat(Result3). Distinct).ToArray
' luego instancias un segundo array que obtiene los números que no están dentro del rango 'Xmin'-'Xmax' del primer array: Dim NumbersNotInRange As Integer() = GetNumbersNotInRange(Result11, Xmin, XMax).ToArray
' Y por último reemplazas los números que no están en el rango, en el primer array: Result11 =Result11.Select(Function(Value As Integer) ReadOnly If(Value < MAX, Value, Rand.Next(0, MAX)) <-----error de sobrecarga porque ninguna seleccion selet se puede llamar a las que se tiene acceso se puede llamar con estos argumentos End Function))
' y los añades a los listbox: ListBox1.Items.AddRange(Result11.Cast(Of Object).ToArray) ListBox2.Items.AddRange(NumbersNotInRange.Cast(Of Object).ToArray)
Luis
|
|
|
389
|
Programación / .NET (C#, VB.NET, ASP) / Re: Como puedo saber los números que faltan dentro del rango ?
|
en: 21 Enero 2014, 16:54 pm
|
Nada dos dias y nada no logro hacerlo funcionar Public Class Form1 Dim XMax As Short = 99 Dim Xmin As Short = 0 Dim x As Integer = 0 Dim Número As Double Private TextBoxes As TextBox() = {Nothing} Private Result1 As Int32(), Result2 As Int32(), Result3 As Int32() Private _textBox As Object Private _getNumbersNotInRange As Object Private Property ListBox1Count As Integer ReadOnly MAX As Integer = 99 Private Property Calcular As Object Private Property TextBox(ByVal TextBoxCount As Short) As Object Get Return _textBox End Get Set(ByVal value As Object) _textBox = value End Set End Property ReadOnly Property Num1 As Int32 Get Return CInt(TextBox1.Text) End Get End Property ReadOnly Property Num2 As Int32 Get Return CInt(TextBox2.Text) End Get End Property ReadOnly Property Num3 As Int32 Get Return CInt(TextBox3.Text) End Get End Property Private Property GetNumbersNotInRange(ByVal Result11 As IEnumerable(Of Integer), ByVal Xmin As Integer, ByVal XMax As Integer) As Object Get Return _getNumbersNotInRange End Get Set(ByVal value As Object) _getNumbersNotInRange = value End Set End Property Private Sub Sumar(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click Result1 = {Num1 + 10, Num1 + 20, Num1 + 30} _ .Distinct().ToArray ' Elimino duplicados Result2 = {Num2 + 10, Num2 + 20, Num2 + 30} _ .Distinct().ToArray ' Elimino duplicados Result3 = {Num3 + 10, Num3 + 20, Num3 + 30} _ .Distinct().ToArray ' Elimino duplicados ' primero concatenas y eliminas duplicados en el primer array: Dim Result11 As IEnumerable(Of Integer) = (Result1.Concat(Result3).Concat(Result3). Distinct).ToArray ' luego instancias un segundo array que obtiene los números que no están dentro del rango 'Xmin'-'Xmax' del primer array: Dim NumbersNotInRange As Integer() = GetNumbersNotInRange(Result11, Xmin, XMax).ToArray ' Y por último reemplazas los números que no están en el rango, en el primer array: Result11 =Result11.Select(Function(Value As Integer) ReadOnly If(Value < MAX, Value, Rand.Next(0, MAX)) End Function)) ' y los añades a los listbox: ListBox1.Items.AddRange(Result11.Cast(Of Object).ToArray) ListBox2.Items.AddRange(NumbersNotInRange.Cast(Of Object).ToArray) End Sub End Class
Luis
|
|
|
390
|
Programación / .NET (C#, VB.NET, ASP) / Re: Como puedo saber los números que faltan dentro del rango ?
|
en: 19 Enero 2014, 09:44 am
|
Aquí no es necesario el sarcasmo, primero habla del rango, pero luego según dice: 'me gustaria mostrar en otro listbox los números que " NO " están dentro de estas sumas', como ves no dice: 'los números que NO están dentro del rango'.
Si tu comprendes lo que significa "un número que no está dentro de una suma", me parece bien, aunque digo yo que si sumas 1+1 todo el resto de números existentes estarán fuera de la suma, así que a dudas poco detalladas prefiero preguntar para estar seguro de lo que quiere.
Saludos
Hola No vi anoche el tema jej Si Elektro si la función ( pondré corto los números) me da" 2, 4 ,6,8, 9 " y el rango es de 0 al 10 entonces me faltaría el " 1,3, 5, 7 " ademas de mostrar " 2, 4 ,6,8, 9 " también quiero mostrar " 1,3, 5, 7 " pero en otro listbox Luis
|
|
|
|
|
|
|