Autor
|
Tema: Error en variable ??? (Leído 2,806 veces)
|
luis456
Desconectado
Mensajes: 551
|
Estoy trabajno este codigo y me da error en cols y no descubro el porque ? ya que lo declaro ?? Error 2 'cols' no está declarado. Puede que esté inaccesible debido a su nivel de protección. Public Class Form1 Dim maxo As Integer = 7 Dim valuesInta As IEnumerable(Of Integer) 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, 3, 4, 5, 6, 9} 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 MsgBox(String.Join(", ", pairs(0).Value)) MsgBox(String.Join(", ", pairs(1).Value)) MsgBox(String.Join(", ", pairs(2).Value)) MsgBox(String.Join(", ", pairs(3).Value)) Dim M1 As IEnumerable(Of Integer) = pairs(0).Value.ToList Dim juntos2 As List(Of Integer) = M1 juntos2.Sort() Me.ListBox2.Items.AddRange((From value As Integer In M1).Cast(Of Object).ToArray) Dim M2 As IEnumerable(Of Integer) = pairs(1).Value.ToList Dim juntos3 As List(Of Integer) = M2 juntos3.Sort() 'Me.ListBox2.Items.AddRange((From value As Integer In M1).Cast(Of Object).ToArray) Dim M3 As IEnumerable(Of Integer) = pairs(2).Value.ToList Dim juntos4 As List(Of Integer) = M3 juntos4.Sort() Dim M4 As IEnumerable(Of Integer) = pairs(3).Value.ToList Dim juntos5 As List(Of Integer) = M4 juntos5.Sort() 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 col Where (index <> value) AndAlso (CInt(value & index) <= maxValue) Select CInt(value & index)) End If End Function Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim cols As IEnumerable(Of IEnumerable(Of String)) = From col As IEnumerable(Of Integer) In {juntos2, juntos3, juntos4, juntos5}.Distinct.ToList Where (col.Count() = maxo) Group By String.Join("", col).AsEnumerable Into(Group) Select From value As Integer In Group.First.Distinct Select value.ToString(format:="0#") Me.ListBox2.Items.AddRange((From cols As IEnumerable(Of String) In cols Select String.Join(", ", col)).ToArray) [color=red]<-----ACA ME DA EL ERROR[/color] ' MsgBox(cols.Count) End Sub End Class
se supone que ya lo declaro y en otro codigo si me funciona bien luis
|
|
« Última modificación: 9 Octubre 2015, 15:42 pm por luis456 »
|
En línea
|
Que tu sabiduria no sea motivo de Humillacion para los demas
|
|
|
luis456
Desconectado
Mensajes: 551
|
SOLUCIONADO Public Class Form1 Dim maxo As Integer = 7 Dim valuesInta As IEnumerable(Of Integer) 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, 3, 4, 5, 6, 9} 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 MsgBox(String.Join(", ", pairs(0).Value)) MsgBox(String.Join(", ", pairs(1).Value)) MsgBox(String.Join(", ", pairs(2).Value)) MsgBox(String.Join(", ", pairs(3).Value)) Dim M1 As IEnumerable(Of Integer) = pairs(0).Value.ToList Dim juntos2 As List(Of Integer) = M1 juntos2.Sort() 'Me.ListBox2.Items.AddRange((From value As Integer In M1).Cast(Of Object).ToArray) Dim M2 As IEnumerable(Of Integer) = pairs(1).Value.ToList Dim juntos3 As List(Of Integer) = M2 juntos3.Sort() 'Me.ListBox2.Items.AddRange((From value As Integer In M1).Cast(Of Object).ToArray) Dim M3 As IEnumerable(Of Integer) = pairs(2).Value.ToList Dim juntos4 As List(Of Integer) = M3 juntos4.Sort() Dim M4 As IEnumerable(Of Integer) = pairs(3).Value.ToList Dim juntos5 As List(Of Integer) = M4 juntos5.Sort() Dim cols As IEnumerable(Of IEnumerable(Of String)) = From col As IEnumerable(Of Integer) In {juntos2, juntos3, juntos4, juntos5}.Distinct.ToList Where (col.Count() = maxo) Group By String.Join("", col).AsEnumerable Into Group Select From value As Integer In Group.First.Distinct Select value.ToString(format:="0#") ListBox2.Items.AddRange((From col As IEnumerable(Of String) In cols Select String.Join(", ", col)).ToArray) MsgBox(cols.Count) 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 col Where (index <> value) AndAlso (CInt(value & index) <= maxValue) Select CInt(value & index)) End If End Function End Class
Luis
|
|
|
En línea
|
Que tu sabiduria no sea motivo de Humillacion para los demas
|
|
|
|
Mensajes similares |
|
Asunto |
Iniciado por |
Respuestas |
Vistas |
Último mensaje |
|
|
error al hacer una variable
PHP
|
LightHades
|
6
|
3,059
|
7 Junio 2009, 18:31 pm
por LightHades
|
|
|
Error 91: Variable de tipo object o la variable de bloque with no esta estableci
Programación Visual Basic
|
brus_k10
|
2
|
6,616
|
16 Junio 2009, 16:20 pm
por cassiani
|
|
|
error de variable scalar
.NET (C#, VB.NET, ASP)
|
SAGA-gl
|
1
|
1,971
|
9 Julio 2014, 21:03 pm
por fran800m
|
|
|
error en variable php
PHP
|
d91
|
2
|
1,930
|
5 Enero 2015, 06:42 am
por Shell Root
|
|
|
Error en variable @PathFile en Bulk SQL SERVER
Bases de Datos
|
Zeroql
|
0
|
1,902
|
7 Enero 2018, 19:27 pm
por Zeroql
|
|