elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: (TUTORIAL) Aprende a emular Sentinel Dongle By Yapis


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  comoparar pares de celdas en control msflexgrid
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: comoparar pares de celdas en control msflexgrid  (Leído 3,064 veces)
magomi

Desconectado Desconectado

Mensajes: 22


EGO SUM ARS


Ver Perfil WWW
comoparar pares de celdas en control msflexgrid
« en: 9 Agosto 2009, 00:33 am »

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.
Código:
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


form2



« Última modificación: 9 Agosto 2009, 00:48 am por seba123neo » En línea

seba123neo
Moderador
***
Desconectado Desconectado

Mensajes: 3.621



Ver Perfil WWW
Re: comoparar pares de celdas en control msflexgrid
« Respuesta #1 en: 9 Agosto 2009, 00:52 am »

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.


En línea

magomi

Desconectado Desconectado

Mensajes: 22


EGO SUM ARS


Ver Perfil WWW
Re: comoparar pares de celdas en control msflexgrid
« Respuesta #2 en: 9 Agosto 2009, 01:46 am »

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
En línea

seba123neo
Moderador
***
Desconectado Desconectado

Mensajes: 3.621



Ver Perfil WWW
Re: comoparar pares de celdas en control msflexgrid
« Respuesta #3 en: 9 Agosto 2009, 02:49 am »

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).

Código
  1. Option Explicit
  2.  
  3. Private Sub Command1_Click()
  4.   Call Comparar(MSFlexGrid1, MSFlexGrid2)
  5. End Sub
  6.  
  7. Private Function Comparar(ByVal pFlexgrid1 As MSFlexGrid, ByVal pFlexgrid2 As MSFlexGrid)
  8.   Dim i As Long, a As Long
  9.   Dim vNi As String, vNF As String, vLongitud As String
  10.  
  11.   With pFlexgrid1
  12.      For i = 1 To .Rows - 1
  13.         vNi = .TextMatrix(i, 0)
  14.         vNF = .TextMatrix(i, 1)
  15.         vLongitud = .TextMatrix(i, 2)
  16.         For a = 1 To pFlexgrid2.Rows - 1
  17.            If pFlexgrid2.TextMatrix(a, 0) = vNi And pFlexgrid2.TextMatrix(a, 1) = vNF Then
  18.                  pFlexgrid2.TextMatrix(a, 2) = vLongitud
  19.            End If
  20.         Next a
  21.      Next i
  22.   End With
  23. End Function
  24.  
  25. Private Sub Form_Load()
  26.   With MSFlexGrid1
  27.      .FixedCols = 0
  28.      .FormatString = "NI|NF|Long. en m"
  29.  
  30.      .AddItem "M" & vbTab & "A" & vbTab & "22"
  31.      .AddItem "A" & vbTab & "B" & vbTab & "33"
  32.      .AddItem "B" & vbTab & "C" & vbTab & "44"
  33.      .AddItem "B" & vbTab & "D" & vbTab & "55"
  34.  
  35.      .ColWidth(0) = 700
  36.      .ColWidth(1) = 1000
  37.      .ColWidth(2) = 1000
  38.  
  39.      .RemoveItem 1
  40.   End With
  41.  
  42.   With MSFlexGrid2
  43.      .FixedCols = 0
  44.      .FormatString = "NI|NF|Long. en m"
  45.  
  46.      .AddItem "M" & vbTab & "A"
  47.      .AddItem "B" & vbTab & "D"
  48.  
  49.      .ColWidth(0) = 700
  50.      .ColWidth(1) = 1000
  51.      .ColWidth(2) = 1000
  52.  
  53.      .RemoveItem 1
  54.   End With
  55. End Sub
  56.  

saludos.
En línea

magomi

Desconectado Desconectado

Mensajes: 22


EGO SUM ARS


Ver Perfil WWW
Re: comoparar pares de celdas en control msflexgrid
« Respuesta #4 en: 9 Agosto 2009, 03:53 am »

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
En línea

seba123neo
Moderador
***
Desconectado Desconectado

Mensajes: 3.621



Ver Perfil WWW
Re: comoparar pares de celdas en control msflexgrid
« Respuesta #5 en: 9 Agosto 2009, 04:45 am »

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
En línea

BlackZeroX
Wiki

Desconectado Desconectado

Mensajes: 3.158


I'Love...!¡.


Ver Perfil WWW
Re: comoparar pares de celdas en control msflexgrid
« Respuesta #6 en: 9 Agosto 2009, 04:57 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.
En línea

The Dark Shadow is my passion.
magomi

Desconectado Desconectado

Mensajes: 22


EGO SUM ARS


Ver Perfil WWW
Re: comoparar pares de celdas en control msflexgrid
« Respuesta #7 en: 10 Agosto 2009, 00:15 am »

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
En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines