Hola a todos...
Tengo un problemilla que le he dado vueltas y no he podido resolver...
resulta que tengo 2 msflexgrid en form diferentes. en el form1 el msflexgrid tiene de columnas NI(nodo inicial), NF(nodo final) y Logintud. Cabe destacar que en el form1 hay 1 textbox y un boton y depende de la cantidad que meta en el textbox y apriete el boton saldran tantas filas como haya introducido en el textbox....( eso ya lo tengo solucionado) seguimos con el problema en el msflexgrid del form2 tambien tengo las mismas columnas (NI,NF,longitud) y hace lo mismo con el textbox pero en este caso el numero de filas puede ser menor o igual al numero de filas del msflexgrid del form 1... la pregunta es la siguiente:
Como hago para comparar als columnas NI y NF(esas 2 comlumnas) del msflexgrid del form1 con las columnas NI y NF y depende de si son iguales o no traerme la longitud de la columna del msdflexgrid del form1 al msflexgrid del form2...
Nota: en el form1 los datos a introducir son NI , ND y longitud y en el form2 solo introduzco el NI y NF y al apretar un boton la longitud me la deberia traer del msflexgrid del form1..
Aqui adjunto el codigo con el que he tratado...
He hecho con 2 for pero me da el mismo resultado he aqui el primer code que use.
Private Sub longitud()
For i = 1 To Val(Text1.Text)
If frmtramos.MSFlexGrid1.Rows > 0 And Text1.Text > 0 Then
If MSFlexGrid1.TextMatrix(i, 0) = frmtramos.MSFlexGrid1.TextMatrix(1, 1) And MSFlexGrid1.TextMatrix(i, 1) = frmtramos.MSFlexGrid1.TextMatrix(1, 2) Then
MSFlexGrid1.TextMatrix(i, 2) = frmtramos.MSFlexGrid1.TextMatrix(1, 3)
Else
If frmtramos.MSFlexGrid1.Rows > 1 And Text1.Text > 1 Then
If MSFlexGrid1.TextMatrix(i, 0) = frmtramos.MSFlexGrid1.TextMatrix(2, 1) And MSFlexGrid1.TextMatrix(i, 1) = frmtramos.MSFlexGrid1.TextMatrix(2, 2) Then
MSFlexGrid1.TextMatrix(i, 2) = frmtramos.MSFlexGrid1.TextMatrix(2, 3)
Else
If frmtramos.MSFlexGrid1.Rows > 2 And Text1.Text > 2 Then
If MSFlexGrid1.TextMatrix(i, 0) = frmtramos.MSFlexGrid1.TextMatrix(3, 1) And MSFlexGrid1.TextMatrix(i, 1) = frmtramos.MSFlexGrid1.TextMatrix(3, 2) Then
MSFlexGrid1.TextMatrix(i, 2) = frmtramos.MSFlexGrid1.TextMatrix(3, 3)
Else
If frmtramos.MSFlexGrid1.Rows > 3 And Text1.Text > 3 Then
If MSFlexGrid1.TextMatrix(i, 0) = frmtramos.MSFlexGrid1.TextMatrix(4, 1) And MSFlexGrid1.TextMatrix(i, 1) = frmtramos.MSFlexGrid1.TextMatrix(4, 2) Then
MSFlexGrid1.TextMatrix(i, 2) = frmtramos.MSFlexGrid1.TextMatrix(4, 3)
Else
If frmtramos.MSFlexGrid1.Rows > 4 And Text1.Text > 4 Then
If MSFlexGrid1.TextMatrix(i, 0) = frmtramos.MSFlexGrid1.TextMatrix(5, 1) And MSFlexGrid1.TextMatrix(i, 1) = frmtramos.MSFlexGrid1.TextMatrix(5, 2) Then
MSFlexGrid1.TextMatrix(i, 2) = frmtramos.MSFlexGrid1.TextMatrix(5, 3)
Else
If frmtramos.MSFlexGrid1.Rows > 5 And Text1.Text > 5 Then
If MSFlexGrid1.TextMatrix(i, 0) = frmtramos.MSFlexGrid1.TextMatrix(6, 1) And MSFlexGrid1.TextMatrix(i, 1) = frmtramos.MSFlexGrid1.TextMatrix(6, 2) Then
MSFlexGrid1.TextMatrix(i, 2) = frmtramos.MSFlexGrid1.TextMatrix(6, 3)
Else
If frmtramos.MSFlexGrid1.Rows > 6 And Text1.Text > 6 Then
If MSFlexGrid1.TextMatrix(i, 0) = frmtramos.MSFlexGrid1.TextMatrix(7, 1) And MSFlexGrid1.TextMatrix(i, 1) = frmtramos.MSFlexGrid1.TextMatrix(7, 2) Then
MSFlexGrid1.TextMatrix(i, 2) = frmtramos.MSFlexGrid1.TextMatrix(7, 3)
Else
If frmtramos.MSFlexGrid1.Rows > 7 And Text1.Text > 7 Then
If MSFlexGrid1.TextMatrix(i, 0) = frmtramos.MSFlexGrid1.TextMatrix(8, 1) And MSFlexGrid1.TextMatrix(i, 1) = frmtramos.MSFlexGrid1.TextMatrix(8, 2) Then
MSFlexGrid1.TextMatrix(i, 2) = frmtramos.MSFlexGrid1.TextMatrix(8, 3)
Else
If frmtramos.MSFlexGrid1.Rows > 8 And Text1.Text > 8 Then
If MSFlexGrid1.TextMatrix(i, 0) = frmtramos.MSFlexGrid1.TextMatrix(9, 1) And MSFlexGrid1.TextMatrix(i, 1) = frmtramos.MSFlexGrid1.TextMatrix(9, 2) Then
MSFlexGrid1.TextMatrix(i, 2) = frmtramos.MSFlexGrid1.TextMatrix(9, 3)
Else
If frmtramos.MSFlexGrid1.Rows > 9 And Text1.Text > 9 Then
If MSFlexGrid1.TextMatrix(i, 0) = frmtramos.MSFlexGrid1.TextMatrix(10, 1) And MSFlexGrid1.TextMatrix(i, 1) = frmtramos.MSFlexGrid1.TextMatrix(10, 2) Then
MSFlexGrid1.TextMatrix(i, 2) = frmtramos.MSFlexGrid1.TextMatrix(10, 3)
Else
If frmtramos.MSFlexGrid1.Rows > 10 And Text1.Text > 10 Then
If MSFlexGrid1.TextMatrix(i, 0) = frmtramos.MSFlexGrid1.TextMatrix(11, 1) And MSFlexGrid1.TextMatrix(i, 1) = frmtramos.MSFlexGrid1.TextMatrix(11, 2) Then
MSFlexGrid1.TextMatrix(i, 2) = frmtramos.MSFlexGrid1.TextMatrix(11, 3)
Else
If frmtramos.MSFlexGrid1.Rows > 11 And Text1.Text > 11 Then
If MSFlexGrid1.TextMatrix(i, 0) = frmtramos.MSFlexGrid1.TextMatrix(12, 1) And MSFlexGrid1.TextMatrix(i, 1) = frmtramos.MSFlexGrid1.TextMatrix(12, 2) Then
MSFlexGrid1.TextMatrix(i, 2) = frmtramos.MSFlexGrid1.TextMatrix(12, 3)
Else
If frmtramos.MSFlexGrid1.Rows > 12 And Text1.Text > 12 Then
If MSFlexGrid1.TextMatrix(i, 0) = frmtramos.MSFlexGrid1.TextMatrix(13, 1) And MSFlexGrid1.TextMatrix(i, 1) = frmtramos.MSFlexGrid1.TextMatrix(13, 2) Then
MSFlexGrid1.TextMatrix(i, 2) = frmtramos.MSFlexGrid1.TextMatrix(13, 3)
Else
If frmtramos.MSFlexGrid1.Rows > 13 And Text1.Text > 13 Then
If MSFlexGrid1.TextMatrix(i, 0) = frmtramos.MSFlexGrid1.TextMatrix(14, 1) And MSFlexGrid1.TextMatrix(i, 1) = frmtramos.MSFlexGrid1.TextMatrix(14, 2) Then
MSFlexGrid1.TextMatrix(i, 2) = frmtramos.MSFlexGrid1.TextMatrix(14, 3)
Else
If frmtramos.MSFlexGrid1.Rows > 14 And Text1.Text > 14 Then
If MSFlexGrid1.TextMatrix(i, 0) = frmtramos.MSFlexGrid1.TextMatrix(15, 1) And MSFlexGrid1.TextMatrix(i, 1) = frmtramos.MSFlexGrid1.TextMatrix(15, 2) Then
MSFlexGrid1.TextMatrix(i, 2) = frmtramos.MSFlexGrid1.TextMatrix(15, 3)
Else
If frmtramos.MSFlexGrid1.Rows > 15 And Text1.Text > 15 Then
If MSFlexGrid1.TextMatrix(i, 0) = frmtramos.MSFlexGrid1.TextMatrix(16, 1) And MSFlexGrid1.TextMatrix(i, 1) = frmtramos.MSFlexGrid1.TextMatrix(16, 2) Then
MSFlexGrid1.TextMatrix(i, 2) = frmtramos.MSFlexGrid1.TextMatrix(16, 3)
Else
If frmtramos.MSFlexGrid1.Rows > 16 And Text1.Text > 16 Then
If MSFlexGrid1.TextMatrix(i, 0) = frmtramos.MSFlexGrid1.TextMatrix(17, 1) And MSFlexGrid1.TextMatrix(i, 1) = frmtramos.MSFlexGrid1.TextMatrix(17, 2) Then
MSFlexGrid1.TextMatrix(i, 2) = frmtramos.MSFlexGrid1.TextMatrix(17, 3)
Else
MsgBox "Eso no es un tramo", 48, "Atencion"
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
Next i
aqui adjunto las fotos de los 2 form ( o la parte que me interesa que me ayuden)
form1
(http://img529.imageshack.us/img529/6993/79083046.jpg) (http://img529.imageshack.us/i/79083046.jpg/)
form2
(http://img140.imageshack.us/img140/598/99996714.jpg) (http://img140.imageshack.us/i/99996714.jpg/)
Hola, mamita querida es una "tormenta" de if y mal indentados para colmo,entiendo lo que queres hacer, pero no entiendo varias cosas,¿ los datos de donde los sacas? de ¿ una base ? ¿ porque cuando pones que te traiga 2 en el form2, te trae la primer columna y la cuarta columna del form1 ? no es dificil tenes que hacerte una funcion que haga todo, pero necesito saber eso antes de poder ver como se hace...no quiere decir que te la voy a ahcer solo orientarte :xD
saludos.
gracias por responder.. bueno explico un poco mejor..
en el form 1 los datos los introcue el usuario... Ni,NF y longitud....
y en el form 2 solo introduce NI y NF y con el boton compara y me trae las longitudes del form1
bueno, con una simple funcion se puede hacer, mira lo que es mi codigo a comparación de lo que hacias...fijate y entende que es lo que hace para la proxima ya saber mas...lo que hice fue un proyecto nuevo y agregar datos a 2 flexgrid del mismo formulario, le puse los mismos datos que vos posteaste en la foto...(en tu caso es en diferentes formularios pero es lo mismo).
Option Explicit
Private Sub Command1_Click()
Call Comparar(MSFlexGrid1, MSFlexGrid2)
End Sub
Private Function Comparar(ByVal pFlexgrid1 As MSFlexGrid, ByVal pFlexgrid2 As MSFlexGrid)
Dim i As Long, a As Long
Dim vNi As String, vNF As String, vLongitud As String
With pFlexgrid1
For i = 1 To .Rows - 1
vNi = .TextMatrix(i, 0)
vNF = .TextMatrix(i, 1)
vLongitud = .TextMatrix(i, 2)
For a = 1 To pFlexgrid2.Rows - 1
If pFlexgrid2.TextMatrix(a, 0) = vNi And pFlexgrid2.TextMatrix(a, 1) = vNF Then
pFlexgrid2.TextMatrix(a, 2) = vLongitud
End If
Next a
Next i
End With
End Function
Private Sub Form_Load()
With MSFlexGrid1
.FixedCols = 0
.FormatString = "NI|NF|Long. en m"
.AddItem "M" & vbTab & "A" & vbTab & "22"
.AddItem "A" & vbTab & "B" & vbTab & "33"
.AddItem "B" & vbTab & "C" & vbTab & "44"
.AddItem "B" & vbTab & "D" & vbTab & "55"
.ColWidth(0) = 700
.ColWidth(1) = 1000
.ColWidth(2) = 1000
.RemoveItem 1
End With
With MSFlexGrid2
.FixedCols = 0
.FormatString = "NI|NF|Long. en m"
.AddItem "M" & vbTab & "A"
.AddItem "B" & vbTab & "D"
.ColWidth(0) = 700
.ColWidth(1) = 1000
.ColWidth(2) = 1000
.RemoveItem 1
End With
End Sub
saludos.
gracias por tu respuesta esta muy acertada esa explicacion... pero ahora tengo otro problema debido a q soy tan newie.... no se como asociar los msflexgrid en diferentes forms- - :S
mmm no vendria mal un poco de practica y prueba no y un manual de paso ?? podes poner como publica la funcion en un modulo y despues llamarla desde el form2 y pasarle los flexgrid anteponiendo el nombre del formulario form1.flexgrid...etc
Cita de: magomi en 9 Agosto 2009, 00:33 AM
con tu infinidad de "if then" Me recordaste cuando plantie un algoritmo con puro select case ( mas de mil lineas de "select case" y aun asi tenia que revisar coherencias y errores de Dedo--, era frustante ) posteriormente como dijo seba revice un manual y vi la eficiencia de los bucles y de los terminos semejantes que usaba y reduje el codigo a unas 15 lineas sin errores.
muchas gracias ya pude resolverlo.... gracias por la ayuda... quisiera me recomendaran un buen manual o algun libro que hable sobre ese tipo de bucles me ahorraria mucho jaj nada mas con ver el desastre que tenia jaja