Resumir Código
Hola, tengo el siguiente código, y me parece excesivamente largo.Se que se puede resumir con matrices, funciones..., pero el caso es que no soy muy experta, y me cuesta mucho, cada vez que genero código.Podrian darme algun consejo, o bien recomendarme algún manual, o tutorial por internet?
Gracias ;-)
Dim A As String
Dim B As String
Dim C As String
Dim D As String
Dim E As String
Dim F As String
Dim G As String
Dim H As String
Dim I As String
Dim J As String
Private Sub text17_lostfocus()
Text17.Text = FormatNumber(Val(Text17.Text), 2, 0, 0, 0)
End Sub
Private Sub text18_lostfocus()
Text18.Text = FormatNumber(Val(Text18.Text), 2, 0, 0, 0)
End Sub
Private Sub text19_lostfocus()
Text19.Text = FormatNumber(Val(Text19.Text), 2, 0, 0, 0)
End Sub
Private Sub text20_lostfocus()
Text20.Text = FormatNumber(Val(Text20.Text), 2, 0, 0, 0)
End Sub
Private Sub text21_lostfocus()
Text21.Text = FormatNumber(Val(Text21.Text), 2, 0, 0, 0)
End Sub
Private Sub text22_lostfocus()
Text22.Text = FormatNumber(Val(Text22.Text), 2, 0, 0, 0)
End Sub
Private Sub text49_Gotfocus()
A = Val(Text17.Text)
B = Val(Text33.Text)
C = A * B
Text49.Text = FormatNumber(C, 2, 0, 0, 0)
D = Val(Text49.Text)
E = Val(Text50.Text)
F = Val(Text51.Text)
G = Val(Text52.Text)
H = Val(Text53.Text)
I = Val(Text54.Text)
J = D + E + F + G + H + I
Text107.Text = FormatNumber(J, 2, 0, 0, 0)
If Val(Text107.Text) > 0 Then
Check7.Value = 1
Else
Check7.Value = 0
End If
End Sub
Private Sub text50_Gotfocus()
A = Val(Text18.Text)
B = Val(Text34.Text)
C = A * B
Text50.Text = FormatNumber(C, 2, 0, 0, 0)
D = Val(Text49.Text)
E = Val(Text50.Text)
F = Val(Text51.Text)
G = Val(Text52.Text)
H = Val(Text53.Text)
I = Val(Text54.Text)
J = D + E + F + G + H + I
Text107.Text = FormatNumber(J, 2, 0, 0, 0)
If Val(Text107.Text) > 0 Then
Check7.Value = 1
Else
Check7.Value = 0
End If
End Sub
Private Sub text51_Gotfocus()
A = Val(Text19.Text)
B = Val(Text35.Text)
C = A * B
Text51.Text = FormatNumber(C, 2, 0, 0, 0)
D = Val(Text49.Text)
E = Val(Text50.Text)
F = Val(Text51.Text)
G = Val(Text52.Text)
H = Val(Text53.Text)
I = Val(Text54.Text)
J = D + E + F + G + H + I
Text107.Text = FormatNumber(J, 2, 0, 0, 0)
If Val(Text107.Text) > 0 Then
Check7.Value = 1
Else
Check7.Value = 0
End If
End Sub
Private Sub text52_Gotfocus()
A = Val(Text20.Text)
B = Val(Text36.Text)
C = A * B
Text52.Text = FormatNumber(C, 2, 0, 0, 0)
D = Val(Text49.Text)
E = Val(Text50.Text)
F = Val(Text51.Text)
G = Val(Text52.Text)
H = Val(Text53.Text)
I = Val(Text54.Text)
J = D + E + F + G + H + I
Text107.Text = FormatNumber(J, 2, 0, 0, 0)
If Val(Text107.Text) > 0 Then
Check7.Value = 1
Else
Check7.Value = 0
End If
End Sub
Private Sub text53_Gotfocus()
A = Val(Text21.Text)
B = Val(Text37.Text)
C = A * B
Text53.Text = FormatNumber(C, 2, 0, 0, 0)
D = Val(Text49.Text)
E = Val(Text50.Text)
F = Val(Text51.Text)
G = Val(Text52.Text)
H = Val(Text53.Text)
I = Val(Text54.Text)
J = D + E + F + G + H + I
Text107.Text = FormatNumber(J, 2, 0, 0, 0)
If Val(Text107.Text) > 0 Then
Check7.Value = 1
Else
Check7.Value = 0
End If
End Sub
Private Sub text54_Gotfocus()
A = Val(Text22.Text)
B = Val(Text38.Text)
C = A * B
Text54.Text = FormatNumber(C, 2, 0, 0, 0)
D = Val(Text49.Text)
E = Val(Text50.Text)
F = Val(Text51.Text)
G = Val(Text52.Text)
H = Val(Text53.Text)
I = Val(Text54.Text)
J = D + E + F + G + H + I
Text107.Text = FormatNumber(J, 2, 0, 0, 0)
If Val(Text107.Text) > 0 Then
Check7.Value = 1
Else
Check7.Value = 0
End If
End Sub
Private Sub text107_Gotfocus()
D = Val(Text49.Text)
E = Val(Text50.Text)
F = Val(Text51.Text)
G = Val(Text52.Text)
H = Val(Text53.Text)
I = Val(Text54.Text)
J = D + E + F + G + H + I
Text107.Text = FormatNumber(J, 2, 0, 0, 0)
If Val(Text107.Text) > 0 Then
Check7.Value = 1
Else
Check7.Value = 0
End If
End Sub
Gracias ;-)
Dim A As String
Dim B As String
Dim C As String
Dim D As String
Dim E As String
Dim F As String
Dim G As String
Dim H As String
Dim I As String
Dim J As String
Private Sub text17_lostfocus()
Text17.Text = FormatNumber(Val(Text17.Text), 2, 0, 0, 0)
End Sub
Private Sub text18_lostfocus()
Text18.Text = FormatNumber(Val(Text18.Text), 2, 0, 0, 0)
End Sub
Private Sub text19_lostfocus()
Text19.Text = FormatNumber(Val(Text19.Text), 2, 0, 0, 0)
End Sub
Private Sub text20_lostfocus()
Text20.Text = FormatNumber(Val(Text20.Text), 2, 0, 0, 0)
End Sub
Private Sub text21_lostfocus()
Text21.Text = FormatNumber(Val(Text21.Text), 2, 0, 0, 0)
End Sub
Private Sub text22_lostfocus()
Text22.Text = FormatNumber(Val(Text22.Text), 2, 0, 0, 0)
End Sub
Private Sub text49_Gotfocus()
A = Val(Text17.Text)
B = Val(Text33.Text)
C = A * B
Text49.Text = FormatNumber(C, 2, 0, 0, 0)
D = Val(Text49.Text)
E = Val(Text50.Text)
F = Val(Text51.Text)
G = Val(Text52.Text)
H = Val(Text53.Text)
I = Val(Text54.Text)
J = D + E + F + G + H + I
Text107.Text = FormatNumber(J, 2, 0, 0, 0)
If Val(Text107.Text) > 0 Then
Check7.Value = 1
Else
Check7.Value = 0
End If
End Sub
Private Sub text50_Gotfocus()
A = Val(Text18.Text)
B = Val(Text34.Text)
C = A * B
Text50.Text = FormatNumber(C, 2, 0, 0, 0)
D = Val(Text49.Text)
E = Val(Text50.Text)
F = Val(Text51.Text)
G = Val(Text52.Text)
H = Val(Text53.Text)
I = Val(Text54.Text)
J = D + E + F + G + H + I
Text107.Text = FormatNumber(J, 2, 0, 0, 0)
If Val(Text107.Text) > 0 Then
Check7.Value = 1
Else
Check7.Value = 0
End If
End Sub
Private Sub text51_Gotfocus()
A = Val(Text19.Text)
B = Val(Text35.Text)
C = A * B
Text51.Text = FormatNumber(C, 2, 0, 0, 0)
D = Val(Text49.Text)
E = Val(Text50.Text)
F = Val(Text51.Text)
G = Val(Text52.Text)
H = Val(Text53.Text)
I = Val(Text54.Text)
J = D + E + F + G + H + I
Text107.Text = FormatNumber(J, 2, 0, 0, 0)
If Val(Text107.Text) > 0 Then
Check7.Value = 1
Else
Check7.Value = 0
End If
End Sub
Private Sub text52_Gotfocus()
A = Val(Text20.Text)
B = Val(Text36.Text)
C = A * B
Text52.Text = FormatNumber(C, 2, 0, 0, 0)
D = Val(Text49.Text)
E = Val(Text50.Text)
F = Val(Text51.Text)
G = Val(Text52.Text)
H = Val(Text53.Text)
I = Val(Text54.Text)
J = D + E + F + G + H + I
Text107.Text = FormatNumber(J, 2, 0, 0, 0)
If Val(Text107.Text) > 0 Then
Check7.Value = 1
Else
Check7.Value = 0
End If
End Sub
Private Sub text53_Gotfocus()
A = Val(Text21.Text)
B = Val(Text37.Text)
C = A * B
Text53.Text = FormatNumber(C, 2, 0, 0, 0)
D = Val(Text49.Text)
E = Val(Text50.Text)
F = Val(Text51.Text)
G = Val(Text52.Text)
H = Val(Text53.Text)
I = Val(Text54.Text)
J = D + E + F + G + H + I
Text107.Text = FormatNumber(J, 2, 0, 0, 0)
If Val(Text107.Text) > 0 Then
Check7.Value = 1
Else
Check7.Value = 0
End If
End Sub
Private Sub text54_Gotfocus()
A = Val(Text22.Text)
B = Val(Text38.Text)
C = A * B
Text54.Text = FormatNumber(C, 2, 0, 0, 0)
D = Val(Text49.Text)
E = Val(Text50.Text)
F = Val(Text51.Text)
G = Val(Text52.Text)
H = Val(Text53.Text)
I = Val(Text54.Text)
J = D + E + F + G + H + I
Text107.Text = FormatNumber(J, 2, 0, 0, 0)
If Val(Text107.Text) > 0 Then
Check7.Value = 1
Else
Check7.Value = 0
End If
End Sub
Private Sub text107_Gotfocus()
D = Val(Text49.Text)
E = Val(Text50.Text)
F = Val(Text51.Text)
G = Val(Text52.Text)
H = Val(Text53.Text)
I = Val(Text54.Text)
J = D + E + F + G + H + I
Text107.Text = FormatNumber(J, 2, 0, 0, 0)
If Val(Text107.Text) > 0 Then
Check7.Value = 1
Else
Check7.Value = 0
End If
End Sub
mira no entiendo muy bien tu prog. pero veo que mas o menos se trata de guardar valores y después sumarlos o multiplicarlos. Mira las matrices se declaran asi:
dim Matriz( 1 to 10) as integer
Matriz(1)=10
Matriz(2)=20
y asi si quieres un matriz de 2 dimensiones
dim Matriz(1 to 10, 1 to 10) as integer
Matriz(1,1)=10
Matriz(1,2)=20
y asi. Pero so quieres comentarme mas de tu programa mandame un correo a [email protected]
dim Matriz( 1 to 10) as integer
Matriz(1)=10
Matriz(2)=20
y asi si quieres un matriz de 2 dimensiones
dim Matriz(1 to 10, 1 to 10) as integer
Matriz(1,1)=10
Matriz(1,2)=20
y asi. Pero so quieres comentarme mas de tu programa mandame un correo a [email protected]