Solved

VB6 - Transfer  data from 1 grid to another

Posted on 2012-12-23
6
495 Views
Last Modified: 2012-12-27
Hello all

I have this code bellow that transfer data from 1 grid to another.

The issue i have is with this part of the code:
    For z = MSHFlexGrid2.Rows - 1 To 0 Step -1
        For zz = 1 To MSHFlexGrid2.Rows - 1
            If MSHFlexGrid4.TextMatrix(z, 0) = MSHFlexGrid2.TextMatrix(zz, 0) Then

                MSHFlexGrid4.TextMatrix(z, 2) = MSHFlexGrid2.TextMatrix(zz, 1)
                MSHFlexGrid4.Row = z
                MSHFlexGrid4.Col = 1
                MSHFlexGrid4.CellBackColor = &H80FF&

            End If
        Next zz
    Next z

Open in new window


The Preferred carrier column from MSHFlexgrid4 should not have duplicate value. If it was transferred once, it should not show twice based on the DOOR letter.

Then, if for example, in grid 4, i only have 1 door B but in grid 2, i have 4 B door, then it should add a new row, add Door B in column 0 and add the value in column Preferred carrier column from MSHFlexgrid4.

3 grids

How can i do that please?

Thanks again for your help



FULL CODE:
    Dim i As Integer

    For i = 0 To MSHFlexGrid3.Rows - 1
        If MSHFlexGrid3.TextMatrix(i, 0) <> "" Then
            MSHFlexGrid4.TextMatrix(i, 0) = MSHFlexGrid3.TextMatrix(i, 0)
            MSHFlexGrid4.TextMatrix(i, 1) = MSHFlexGrid3.TextMatrix(i, 1)
            MSHFlexGrid4.Rows = MSHFlexGrid4.Rows + 1
        End If
    Next i


    'Delete empty row
    Dim j As Integer
    Dim k As Integer
    Dim sSQL As String
    For k = MSHFlexGrid4.Rows - 1 To 1 Step -1
        sSQL = ""
        For j = 1 To MSHFlexGrid4.Cols - 1
            sSQL = sSQL & Trim(MSHFlexGrid4.TextMatrix(k, j))
        Next
        If Trim(sSQL) = "" Then
            MSHFlexGrid4.RemoveItem k
        End If
        If MSHFlexGrid4.Rows <= 1 Then Exit For
    Next


    Dim z As Integer
    Dim zz As Integer
    MSHFlexGrid4.Cols = MSHFlexGrid4.Cols + 1
    MSHFlexGrid4.TextMatrix(0, 2) = "Preferred Carrier"


    For z = MSHFlexGrid2.Rows - 1 To 0 Step -1
        For zz = 1 To MSHFlexGrid2.Rows - 1
            If MSHFlexGrid4.TextMatrix(z, 0) = MSHFlexGrid2.TextMatrix(zz, 0) Then

                MSHFlexGrid4.TextMatrix(z, 2) = MSHFlexGrid2.TextMatrix(zz, 1)
                MSHFlexGrid4.Row = z
                MSHFlexGrid4.Col = 1
                MSHFlexGrid4.CellBackColor = &H80FF&

            End If
        Next zz
    Next z

Open in new window

0
Comment
Question by:Wilder1626
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 50

Expert Comment

by:Rgonzo1971
ID: 38720392
Hi,

If I  understand it well you trying to do this

Doors Or
Doors2
not repeating the preferred carrier but insert new lines when there are more than in order group.

Right?

Regards
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 38720566
Hi again

I would say your option 2 and also yes to not repeating the preferred carrier but insert new lines when there are more than in order group.

Thank you so much for your help. :)
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 38723889
The final result should look like this

look like this
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 9

Accepted Solution

by:
shorvath earned 500 total points
ID: 38724741
try this

Dim Doors As New Collection
Dim Door_Entry As String
Dim Order_Group() As String
Dim P_Carrier() As String
Dim Carrier() As String

Private Sub Form_Load()


With MSHFlexGrid1
   .FixedCols = 0
   .Cols = 2
   .Rows = 1
   .AddItem "A" & vbTab & "test1", 1
   .AddItem "A" & vbTab & "test2", 2
   .AddItem "A" & vbTab & "test3", 3
   .AddItem "B" & vbTab & "test4", 4
   .AddItem "C" & vbTab & "test5", 5
   .AddItem "C" & vbTab & "test6", 6
   .AddItem "C" & vbTab & "test7", 7
   .FixedRows = 1
   .TextMatrix(0, 0) = "Door"
   .TextMatrix(0, 1) = "Order Group"
End With

With MSHFlexGrid2
   .FixedCols = 0
   .Cols = 2
   .Rows = 1
   .AddItem "A" & vbTab & "test8", 1
   .AddItem "B" & vbTab & "test9", 2
   .AddItem "B" & vbTab & "test10", 3
   .AddItem "B" & vbTab & "test11", 4
   .AddItem "B" & vbTab & "test12", 5
   .AddItem "C" & vbTab & "test13", 6
   .AddItem "C" & vbTab & "test14", 7
   .FixedRows = 1
   .TextMatrix(0, 0) = "Door"
   .TextMatrix(0, 1) = "P Carrier"
End With

With MSHFlexGrid3
   .FixedCols = 0
   .Cols = 2
   .Rows = 1
   .AddItem "A" & vbTab & "test15", 1
   .AddItem "A" & vbTab & "test16", 2
   .AddItem "A" & vbTab & "test17", 3
   .AddItem "A" & vbTab & "test18", 4
   .AddItem "B" & vbTab & "test19", 5
   .AddItem "C" & vbTab & "test20", 6
   .AddItem "C" & vbTab & "test21", 7
   .FixedRows = 1
   .TextMatrix(0, 0) = "Door"
   .TextMatrix(0, 1) = "Carrier"
End With

With MSHFlexGrid4
   .FixedCols = 0
   .Cols = 4
   .FixedRows = 1
   .TextMatrix(0, 0) = "Door"
   .TextMatrix(0, 1) = "Order Group"
   .TextMatrix(0, 2) = "P Carrier"
   .TextMatrix(0, 3) = "Carrier"
End With

End Sub

Private Sub Command1_Click()
Dim Door_Found As Boolean
Dim i As Integer


'get all distinct Doors
For i = 1 To MSHFlexGrid1.Rows - 1
   If MSHFlexGrid1.TextMatrix(i, 0) <> "" Then
      Door_Found = False
      For Each Item In Doors
         If Item = MSHFlexGrid1.TextMatrix(i, 0) Then
            Door_Found = True
            Exit For
         End If
      Next
     
      If Door_Found = False Then
         Doors.Add MSHFlexGrid1.TextMatrix(i, 0)
      End If
   End If
Next i


For Each Item In Doors

   'check Order Group Tests
   ReDim Order_Group(0 To 0)
   For i = 1 To MSHFlexGrid1.Rows - 1
      If MSHFlexGrid1.TextMatrix(i, 0) <> "" Then
         If Item = MSHFlexGrid1.TextMatrix(i, 0) Then
            Order_Group(UBound(Order_Group())) = MSHFlexGrid1.TextMatrix(i, 1)
            ReDim Preserve Order_Group(0 To UBound(Order_Group()) + 1)
         End If
      End If
   Next i
   
   'check P Carrier Test
   ReDim P_Carrier(0 To 0)
   For i = 1 To MSHFlexGrid2.Rows - 1
      If MSHFlexGrid2.TextMatrix(i, 0) <> "" Then
         If Item = MSHFlexGrid2.TextMatrix(i, 0) Then
            P_Carrier(UBound(P_Carrier())) = MSHFlexGrid2.TextMatrix(i, 1)
            ReDim Preserve P_Carrier(0 To UBound(P_Carrier()) + 1)
         End If
      End If
   Next i
   
   
   'check Carrier Test
   ReDim Carrier(0 To 0)
   For i = 1 To MSHFlexGrid3.Rows - 1
      If MSHFlexGrid3.TextMatrix(i, 0) <> "" Then
         If Item = MSHFlexGrid3.TextMatrix(i, 0) Then
            Carrier(UBound(Carrier())) = MSHFlexGrid3.TextMatrix(i, 1)
            ReDim Preserve Carrier(0 To UBound(Carrier()) + 1)
         End If
      End If
   Next i
   
   
   j = 0
   Door_Entry = ""
   Do While j < UBound(Order_Group()) Or _
            j < UBound(P_Carrier()) Or _
            j < UBound(Carrier())
         
      Door_Entry = Item
     
      If j < UBound(Order_Group()) Then
         Door_Entry = Door_Entry & vbTab & Order_Group(j)
      Else
         Door_Entry = Door_Entry & vbTab & " "
      End If

      If j < UBound(P_Carrier()) Then
         Door_Entry = Door_Entry & vbTab & P_Carrier(j)
      Else
         Door_Entry = Door_Entry & vbTab & " "
      End If
     
      If j < UBound(Carrier()) Then
         Door_Entry = Door_Entry & vbTab & Carrier(j)
      Else
         Door_Entry = Door_Entry & vbTab & " "
      End If
     
      j = j + 1
      MSHFlexGrid4.AddItem Door_Entry
   Loop
   MSHFlexGrid4.AddItem ""
Next




End Sub
0
 
LVL 9

Expert Comment

by:shorvath
ID: 38724746
This is also the follow up code to your next post.
0
 
LVL 11

Author Closing Comment

by:Wilder1626
ID: 38725093
Thank you so much again for your help.

:-)
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
bit defender blocks good applications 2 107
clicking a shape in a frame array vb6 3 48
Passing a Text Box name to a Sub 6 102
RUNRMTCMD from AS/400 13 101
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question