Ver Mensaje Individual
  #1 (permalink)  
Antiguo 04/10/2006, 04:16
Avatar de SuperPinwi
SuperPinwi
 
Fecha de Ingreso: septiembre-2005
Mensajes: 317
Antigüedad: 18 años, 7 meses
Puntos: 1
Corregir el error: "Object reference not set to an instance of an object"

Hola amigos,

Tengo una propiedad a la cual necesito llamar desde un hilo, la propiedad se define así:

Código:
Public Shared Property manejaLabel(ByVal etiquetas() As Label, ByVal nEtiqueta As Integer) As String
        Get
            Return etiquetas(nEtiqueta).Text
        End Get
        Set(ByVal Value As String)
            MessageBox.Show("Llego hasta aquí")
            etiquetas(nEtiqueta).Text = Value
        End Set
    End Property
donde etiquetas es un array de etiquetas en el que voy guardando diferentes valores y nEtiqueta es el indice del array. (Es de tipo Shared porque lo uso desde un hilo).

Lo tengo que llamar desde un hilo, para que me actualice unas etiquetas que se encuentran en el formulario principal. Para ello tengo este bucle:

Código:
For fila = 0 To n - 1
                    'Asignar a las variables el contenido del registro
                    sNombre = dt.Rows(fila)("nombre").ToString
                    nNumero = dt.Rows(fila)("numero").ToString
                    MessageBox.Show(nNumero.ToString)
                    MessageBox.Show("i" & " :" & i)
                    manejaLabel(etiquetas, i) = nNumero
                    i = i + 1
                    'Como sólo hay 8 etiquetas, cada vez que cargue 8, que vuelva a la primera
                    If (i = 8) Then
                        i = 0
                    End If
                Next
y me salta una excepción con el mensaje: "Object variable or with block variable not set" al hacer esto:
Código:
manejaLabel(etiquetas, i) = nNumero
al definir
Dim etiquetas(8) As Label
etiquetas(0) = Label1
etiquetas(1) = Label2
etiquetas(2) = Label3
etiquetas(3) = Label4
etiquetas(4) = Label5
etiquetas(5) = Label6
etiquetas(6) = Label7
etiquetas(7) = Label8


tras definir el array como
Dim etiquetas(8) As System.Windows.Forms.Label
etiquetas(0) = Label1
etiquetas(1) = Label2
etiquetas(2) = Label3
etiquetas(3) = Label4
etiquetas(4) = Label5
etiquetas(5) = Label6
etiquetas(6) = Label7
etiquetas(7) = Label8
la excepción que salta es otra: "Object reference not set to an instance of an object"

nNumero tiene el valor 55 cuando salta la excepción.
¿Sabéis porqué salta? y cómo corregirlo?

Última edición por SuperPinwi; 04/10/2006 a las 04:59 Razón: cambiar título