
05/10/2006, 02:25
|
 | | | Fecha de Ingreso: septiembre-2005
Mensajes: 317
Antigüedad: 19 años, 7 meses Puntos: 1 | |
Aquí tienes el código aunque me acabo de dar cuenta del error... verás, no me permite definir el array como Shared y lo necesito para verlo desde el interior del hilo (y no lo puedo pasar como parámetro porque un hilo no puede llevar parámetros).
si tienes alguna sugerencia te estaré muy agradecida. Lo siento por todas las molestias amigo, ay cada día me veo más torpe con esto
Saludines
Código:
Imports System.Data.OleDb
Imports System
Imports System.Data
Public Class MenuInicial
Inherits System.Windows.Forms.Form
Dim ThreadLeerBD
Dim ThreadActualizaBD
#Region " Código generado por el Diseñador de Windows Forms "
Public Sub New()
MyBase.New()
'El Diseñador de Windows Forms requiere esta llamada.
InitializeComponent()
'Agregar cualquier inicialización después de la llamada a InitializeComponent()
End Sub
'Form reemplaza a Dispose para limpiar la lista de componentes.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Requerido por el Diseñador de Windows Forms
Private components As System.ComponentModel.IContainer
'NOTA: el Diseñador de Windows Forms requiere el siguiente procedimiento
'Puede modificarse utilizando el Diseñador de Windows Forms.
'No lo modifique con el editor de código.
Friend Shared WithEvents Label1 As New System.Windows.Forms.Label
...
Friend Shared WithEvents Label8 As New System.Windows.Forms.Label
Friend WithEvents BLeerBD As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Label1 = New System.Windows.Forms.Label
...
Me.Label8 = New System.Windows.Forms.Label
Me.BLeerBD = New System.Windows.Forms.Button
Me.TxtBxPorcentaje = New System.Windows.Forms.TextBox
Me.SuspendLayout()
'
'Label1
'
Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label1.Location = New System.Drawing.Point(32, 40)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(128, 23)
Me.Label1.TabIndex = 0
Me.Label1.Text = "Label1"
'
...
'Label8
'
Me.Label8.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label8.ForeColor = System.Drawing.SystemColors.HotTrack
Me.Label8.Location = New System.Drawing.Point(32, 376)
Me.Label8.Name = "Label8"
Me.Label8.Size = New System.Drawing.Size(128, 24)
Me.Label8.TabIndex = 7
Me.Label8.Text = "Label8"
'
'
'BLeerBD
'
Me.BLeerBD.BackColor = System.Drawing.SystemColors.InactiveCaption
Me.BLeerBD.ForeColor = System.Drawing.SystemColors.ControlLightLight
Me.BLeerBD.Location = New System.Drawing.Point(320, 104)
Me.BLeerBD.Name = "BLeerBD"
Me.BLeerBD.Size = New System.Drawing.Size(75, 40)
Me.BLeerBD.TabIndex = 8
Me.BLeerBD.Text = "Leer Base De Datos"
'
'BActualizarBD
'
Me.BActualizarBD.BackColor = System.Drawing.SystemColors.InactiveCaption
Me.BActualizarBD.ForeColor = System.Drawing.SystemColors.ControlLightLight
Me.BActualizarBD.Location = New System.Drawing.Point(320, 256)
Me.BActualizarBD.Name = "BActualizarBD"
Me.BActualizarBD.Size = New System.Drawing.Size(80, 48)
Me.BActualizarBD.TabIndex = 9
Me.BActualizarBD.Text = "Actualizar Base de Datos"
'
'MenuInicial
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.BackColor = System.Drawing.SystemColors.InactiveCaptionText
Me.ClientSize = New System.Drawing.Size(424, 430)
Me.Controls.Add(Me.TxtBxPorcentaje)
Me.Controls.Add(Me.BActualizarBD)
Me.Controls.Add(Me.BLeerBD)
Me.Controls.Add(Me.Label8)
...
Me.Controls.Add(Me.Label1)
Me.Menu = Me.MainMenu1
Me.Name = "MenuInicial"
Me.Text = "Aplicación Hilos y Bases de Datos"
Me.ResumeLayout(False)
Dim etiquetas(8) As System.Windows.Forms.Label
'asignamos una etiqueta por cada posición del array
etiquetas(0) = Label1
etiquetas(1) = Label2
etiquetas(2) = Label3
etiquetas(3) = Label4
etiquetas(4) = Label5
etiquetas(5) = Label6
etiquetas(6) = Label7
etiquetas(7) = Label8
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Public Shared Property manejaLabel(ByVal etiquetas() As System.Windows.Forms.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
Private Sub BLeerBD_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BLeerBD.Click
ThreadLeerBD = New System.Threading.Thread(AddressOf Me.EjecutaHiloBD)
ThreadLeerBD.start()
ThreadLeerBD.isBackGround = True
End Sub
'HILO LEE BASE DE DATOS
'descripción: se encarga de leer una base de datos y mostrar por
'pantalla en la interfaz principal los valores que de ella obtiene.
Public Shared Sub EjecutaHiloBD()
'Crea la conexión
Dim objConn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Super.Pinwi\Mis documentos\Mis bases de datos\numeros\numeros.mdb")
Dim objAcciones As New OleDbCommand
Dim dt As DataTable
Dim objAdapter
Dim i As Integer
Dim fila As Integer
Dim n As Integer
Dim sNombre As String
Dim nNumero As Integer
Dim FormMostrar
Dim menu As New MenuInicial
Dim prueba As Integer
Try
'Se abre la conexión de la base de datos
objConn.Open()
'Se escogen los registros de la base de datos que se desean
objAdapter = New OleDbDataAdapter("SELECT * FROM numeros ORDER BY numero", objConn)
'Se almacena la base de datos en el dataTable
dt = New DataTable
objAdapter.Fill(dt)
'Se almacena en n el número de filas de la base de datos
n = dt.Rows.Count
'Se asocia la conexión con el objeto acciones
objAcciones.Connection = objConn
MessageBox.Show("a ve q tiene etiquetas")
'MessageBox.Show(etiquetas(0).Text)
If n = 0 Then
MessageBox.Show("No se ha encontrado ningún registro que coincida con la selección")
Else
'Recorre las filas en el dataTable y las va asignando a las etiquetas
'del formulario principal para que se muestren
For fila = 0 To n - 1
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
End If
objConn.Close()
Catch ex As Exception
MessageBox.Show(Err.Description, "Información del sistema")
End Try
End Sub
End Class
|