Tengo una propiedad a la cual necesito llamar desde un hilo, la propiedad se define así:
Código:
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).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
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:
y me salta una excepción con el mensaje: "Object variable or with block variable not set" al hacer esto: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
Código:
al definir manejaLabel(etiquetas, i) = nNumero
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?