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

 

 


Tema destacado: Curso de javascript por TickTack


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


Desconectado Desconectado

Mensajes: 548



Ver Perfil
Error en variable ???
« en: 9 Octubre 2015, 10:41 am »

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.


 
Código
  1. Public Class Form1
  2.  
  3.    Dim maxo As Integer = 7
  4.  
  5.    Dim valuesInta As IEnumerable(Of Integer)
  6.    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  7.  
  8.        Dim valuesInt As IEnumerable(Of Integer) =
  9.            {0, 1, 2, 3, 4, 5, 6, 9}
  10.  
  11.        Dim pairs As IEnumerable(Of KeyValuePair(Of Integer, IEnumerable(Of Integer))) =
  12.            Form1.GetPairs(valuesInt, maxValue:=80)
  13.  
  14.        For Each pair As KeyValuePair(Of Integer, IEnumerable(Of Integer)) In pairs
  15.  
  16.            ListBox1.Items.Add(String.Format("Key: {0,-4} Values: {1}", pair.Key, String.Join(", ", pair.Value)))
  17.  
  18.        Next pair
  19.  
  20.        MsgBox(String.Join(", ", pairs(0).Value))
  21.        MsgBox(String.Join(", ", pairs(1).Value))
  22.        MsgBox(String.Join(", ", pairs(2).Value))
  23.        MsgBox(String.Join(", ", pairs(3).Value))
  24.  
  25.  
  26.        Dim M1 As IEnumerable(Of Integer) = pairs(0).Value.ToList
  27.        Dim juntos2 As List(Of Integer) = M1
  28.        juntos2.Sort()
  29.        Me.ListBox2.Items.AddRange((From value As Integer In M1).Cast(Of Object).ToArray)
  30.  
  31.        Dim M2 As IEnumerable(Of Integer) = pairs(1).Value.ToList
  32.        Dim juntos3 As List(Of Integer) = M2
  33.        juntos3.Sort()
  34.  
  35.  
  36.        'Me.ListBox2.Items.AddRange((From value As Integer In M1).Cast(Of Object).ToArray)
  37.        Dim M3 As IEnumerable(Of Integer) = pairs(2).Value.ToList
  38.        Dim juntos4 As List(Of Integer) = M3
  39.        juntos4.Sort()
  40.  
  41.        Dim M4 As IEnumerable(Of Integer) = pairs(3).Value.ToList
  42.        Dim juntos5 As List(Of Integer) = M4
  43.        juntos5.Sort()
  44.  
  45.    End Sub
  46.  
  47.    Public Shared Function GetPairs(ByVal col As IEnumerable(Of Integer),
  48.                                    Optional ByVal maxValue As Integer = Integer.MaxValue) As IEnumerable(Of KeyValuePair(Of Integer, IEnumerable(Of Integer)))
  49.  
  50.        If (col.Max >= 10) Then
  51.            Throw New ArgumentException(paramName:="col", Message:="El valor máximo de la colección debe ser un valor inferior a 10.")
  52.  
  53.        Else
  54.  
  55.            Return From value As Integer In col
  56.                   Select New KeyValuePair(Of Integer, IEnumerable(Of Integer))(
  57.                          key:=value,
  58.                          value:=From index As Integer In col
  59.                                 Where (index <> value) AndAlso (CInt(value & index) <= maxValue)
  60.                                 Select CInt(value & index))
  61.  
  62.  
  63.        End If
  64.  
  65.  
  66.  
  67.  
  68.    End Function
  69.  
  70.    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  71.  
  72.         Dim cols As IEnumerable(Of IEnumerable(Of String)) =
  73.      From col As IEnumerable(Of Integer) In {juntos2, juntos3, juntos4, juntos5}.Distinct.ToList Where (col.Count() = maxo)
  74.         Group By String.Join("", col).AsEnumerable
  75.        Into(Group)
  76.        Select From value As Integer In Group.First.Distinct
  77.             Select value.ToString(format:="0#")
  78.  
  79.        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]
  80.  
  81.        ' MsgBox(cols.Count)
  82.    End Sub
  83. 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 Desconectado

Mensajes: 548



Ver Perfil
Re: Error en variable ???
« Respuesta #1 en: 9 Octubre 2015, 15:41 pm »

SOLUCIONADO   :silbar:


Código
  1.  
  2.  
  3. Public Class Form1
  4.  
  5.    Dim maxo As Integer = 7
  6.  
  7.    Dim valuesInta As IEnumerable(Of Integer)
  8.    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  9.  
  10.        Dim valuesInt As IEnumerable(Of Integer) =
  11.            {0, 1, 2, 3, 4, 5, 6, 9}
  12.  
  13.        Dim pairs As IEnumerable(Of KeyValuePair(Of Integer, IEnumerable(Of Integer))) =
  14.            Form1.GetPairs(valuesInt, maxValue:=80)
  15.  
  16.        For Each pair As KeyValuePair(Of Integer, IEnumerable(Of Integer)) In pairs
  17.  
  18.            ListBox1.Items.Add(String.Format("Key: {0,-4} Values: {1}", pair.Key, String.Join(", ", pair.Value)))
  19.  
  20.        Next pair
  21.  
  22.        MsgBox(String.Join(", ", pairs(0).Value))
  23.        MsgBox(String.Join(", ", pairs(1).Value))
  24.        MsgBox(String.Join(", ", pairs(2).Value))
  25.        MsgBox(String.Join(", ", pairs(3).Value))
  26.  
  27.  
  28.        Dim M1 As IEnumerable(Of Integer) = pairs(0).Value.ToList
  29.        Dim juntos2 As List(Of Integer) = M1
  30.        juntos2.Sort()
  31.        'Me.ListBox2.Items.AddRange((From value As Integer In M1).Cast(Of Object).ToArray)
  32.  
  33.        Dim M2 As IEnumerable(Of Integer) = pairs(1).Value.ToList
  34.        Dim juntos3 As List(Of Integer) = M2
  35.        juntos3.Sort()
  36.  
  37.  
  38.        'Me.ListBox2.Items.AddRange((From value As Integer In M1).Cast(Of Object).ToArray)
  39.        Dim M3 As IEnumerable(Of Integer) = pairs(2).Value.ToList
  40.        Dim juntos4 As List(Of Integer) = M3
  41.        juntos4.Sort()
  42.  
  43.        Dim M4 As IEnumerable(Of Integer) = pairs(3).Value.ToList
  44.        Dim juntos5 As List(Of Integer) = M4
  45.        juntos5.Sort()
  46.  
  47.        Dim cols As IEnumerable(Of IEnumerable(Of String)) =
  48.       From col As IEnumerable(Of Integer) In {juntos2, juntos3, juntos4, juntos5}.Distinct.ToList Where (col.Count() = maxo)
  49.      Group By String.Join("", col).AsEnumerable
  50.        Into Group
  51.      Select From value As Integer In Group.First.Distinct
  52.             Select value.ToString(format:="0#")
  53.  
  54.        ListBox2.Items.AddRange((From col As IEnumerable(Of String) In cols Select String.Join(", ", col)).ToArray)
  55.  
  56.        MsgBox(cols.Count)
  57.  
  58.  
  59.  
  60.  
  61.  
  62.    End Sub
  63.  
  64.    Public Shared Function GetPairs(ByVal col As IEnumerable(Of Integer),
  65.                                    Optional ByVal maxValue As Integer = Integer.MaxValue) As IEnumerable(Of KeyValuePair(Of Integer, IEnumerable(Of Integer)))
  66.  
  67.        If (col.Max >= 10) Then
  68.            Throw New ArgumentException(paramName:="col", Message:="El valor máximo de la colección debe ser un valor inferior a 10.")
  69.  
  70.        Else
  71.  
  72.            Return From value As Integer In col
  73.                   Select New KeyValuePair(Of Integer, IEnumerable(Of Integer))(
  74.                          key:=value,
  75.                          value:=From index As Integer In col
  76.                                 Where (index <> value) AndAlso (CInt(value & index) <= maxValue)
  77.                                 Select CInt(value & index))
  78.  
  79.  
  80.        End If
  81.  
  82.  
  83.  
  84.  
  85.    End Function
  86.  
  87.  
  88. End Class


Luis


En línea

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

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
error al hacer una variable
PHP
LightHades 6 2,828 Último mensaje 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,385 Último mensaje 16 Junio 2009, 16:20 pm
por cassiani
error de variable scalar
.NET (C#, VB.NET, ASP)
SAGA-gl 1 1,806 Último mensaje 9 Julio 2014, 21:03 pm
por fran800m
error en variable php
PHP
d91 2 1,774 Último mensaje 5 Enero 2015, 06:42 am
por Shell Root
Error en variable @PathFile en Bulk SQL SERVER
Bases de Datos
Zeroql 0 1,760 Último mensaje 7 Enero 2018, 19:27 pm
por Zeroql
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines