Visual Basic - cómo aplicar el mismo código a distintas matrices?

Life is soft - evento anual de software empresarial
 
Vista:

cómo aplicar el mismo código a distintas matrices?

Publicado por LEO (12 intervenciones) el 30/11/2007 11:23:49
Hola. Tengo un código que crea labels y textboxes en un frame en tiempo de ejecución . Las labels se crean en la matriz lbl1(i) y las textboxes en txt1(i). Quiero simultáneamente se repita esta acción en otros 2 frames más (matrices lbl2(i) y txt2(i) en el 2º frame y lbl3(i) y txt3(i) en el 3º) sin tener que volver a escribir el mismo código para las matrices lbl2(i), txt2(i) y lbl3(i), txt3(i). Seguro que es una tontería, pero no consigo que me salga.

Muchas gracias.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:cómo aplicar el mismo código a distintas matric

Publicado por Carlos (125 intervenciones) el 30/11/2007 17:57:46
Crea un funcion... así

Private function AccionMatrices ()
.
. Aqui haces el procedimiento que crees que se repita
.
.
end function

cada vez que lo necesitas solo lo llamas

Call AccionMatrices

Bueno no se si te solucione el problema
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:cómo aplicar el mismo código a distintas matric

Publicado por LEO (12 intervenciones) el 02/12/2007 11:58:46
Sigue sin salirme. El objetivo es que al clickar el botón cmd(0) lea el nº de objetos a crear en el textbox txtNumSup, y cree esos controles en los 3 frames.
He probado esto:

Private Sub cmd_Click(Index As Integer)
Select Case Index
Case 0
CrearControles lbl1, txt1
CrearControles lbl2, txt2
CrearControles lbl3, txt3
End Select
End Sub

Donde CrearControles es un sub que he metido en un módulo:

Public Sub CrearControles(lbl1 As Label, txt1 As TextBox)
lbl1(0).Visible = True
txt1(0).Visible = True
Do
i = lbl1.Count
If i < 10 Then
Load lbl1(i)
With lbl1(i)
.Top = lbl1(i - 1).Top + 440
.Caption = i + 1
.Visible = True
End With
i = txt1.Count
Load txt1(i)
With txt1(i)
.Top = txt1(i - 1).Top + 440
.Visible = True
End With
ElseIf i = 10 Or i = 20 Then
Load lbl1(i)
With lbl1(i)
.Left = lbl1(i - 1).Left + 880
.Caption = i + 1
.Visible = True
End With
i = txt1.Count
Load txt1(i)
With txt1(i)
.Left = txt1(i - 1).Left + 880
.Visible = True
End With
ElseIf i > 10 And i <> 20 Then
Load lbl1(i)
With lbl1(i)
.Top = lbl1(i - 1).Top + 440
.Left = lbl1(i - 1).Left
.Caption = i + 1
.Visible = True
End With
i = txt1.Count
Load txt1(i)
With txt1(i)
.Top = txt1(i - 1).Top + 440
.Left = txt1(i - 1).Left
.Visible = True
End With

End If
DoEvents
Loop Until i + 1 = Val(txtNumSup.Text)
End Sub

Pero me da el siguient error: "Error de compilación. Se esperaba una variable o un procedimiento, no un módulo."
¿Qué estoy haciendo mal?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar