borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (My VB6 program does not cooperate with a newer version of Access)Next Topic (MILAGE CALCULATOR) New Topic New Poll Post Reply
AndreaVB Forum : VB General : Pls, Help me with msflexgrid comparison of 2 columns!
Poster Message
OLUPHEMMY
Level: Whizz Kid

Registered: 22-05-2007
Posts: 15

icon Pls, Help me with msflexgrid comparison of 2 columns!

I have been designing database related programs using VB6, but I'm now designing an engineering program that will take input from array of rows and columns in MSFLEXGRID I was successfully coded the msflexgrid to take input that is saved to a file and I have done some calculations and result saved in another column. MY PROBLEM NOW LIES IN COMPARING THE VALUE OF IST TWO COLUMNS VALUE. I.E IF THE VALUE OF COLUMN 1=VALUE OF COLUMN 2. A PARTICULAR CONDITION MUST BE MET. E.G
My required result is shown below
COL1,   COL2....................COL8 , COL9
1            2                           0.5     0
2            5 *                       -0.8   -0.3
5            6                          -0.5     0
6            1                           0.9     0
2            3                           0.5     0
3            4                           0.4     0
4            5                           0.5     0
5            2 *                        0.3    0.8
Any row where there is no change of number like 2 & 5, 5 & 2
the result should be zero while the value of the rows where there is change of same number there will be change of Col8 value and sign as shown above.
Please help me to get this result
This is the code I used but i'm not getting the required result.

For i=1 to HowBig
For j=1 to HowBig
  If NodeFrom(i)=NodeTo(j) And NodeTo(i)=NodeFrom(j) Then
PipeDeltaQ(j) = PipeDeltaQ(j)-LooDeltaQ(WLoop(I))End If
grid.TextMatrix(I,9) = PipeDeltaQ(j)
Nextj
Next i


Note all variables are declared and PipeDeltaQ(i) has been calculated for in Col8.
I know you will help me it has been delaying me for weeks now. If somebody need the whole code I will send it to your email address.
Thanks in serious Anticipation

24-05-2007 at 06:59 PM
View Profile Send Email to User Show All Posts | Quote Reply
OLUPHEMMY
Level: Whizz Kid

Registered: 22-05-2007
Posts: 15
icon Msflexgrid column interchange!

I want to please beg if someone can come to my aid this is for my final year project. I will represent this problem again and if someone needs my full code I can sent to the person. I hope i will not be dissapointed for joining andeaVB. This is it again.
I have been designing database related programs using VB6, but I'm now designing an engineering program that will take input from array of rows and columns in MSFLEXGRID I was successfully coded the msflexgrid to take input that is saved to a file and I have done some calculations and result saved in another column. MY PROBLEM NOW LIES IN COMPARING THE VALUE OF IST TWO COLUMNS VALUE. I.E IF THE VALUE OF COLUMN 1=VALUE OF COLUMN 2. A PARTICULAR CONDITION MUST BE MET. E.G
My required result is shown below
NodeFrom.. NodeTo..........................COL8...COL9
1..................  2 .............................  0.5.......0
2..................  5 * ...........................-0.8......-0.3
5..................  6 ..............................-0.5.......0
6..................  1 ...............................0.9.......0
2..................  3 ...............................0.5.......0
3..................  4 ...............................0.4.......0
4..................  5 ...............................0.5.......0
5..................  2 * ............................0.3.......0.8
Any row where there is no change of number like 2 & 5, 5 & 2
the result should be zero while the value of the rows where there is change of same number there will be change of Col8 value with sign as shown above.
Please help me to get this result
This is the code I used but i'm not getting the required result.

For i=1 to HowBig
For j=1 to HowBig
  If NodeFrom(i)=NodeTo(j) And NodeTo(i)=NodeFrom(j) Then
PipeDeltaQ(j) = PipeDeltaQ(j)-LooDeltaQ(WLoop(I))End If
grid.TextMatrix(I,9) = PipeDeltaQ(j)
Nextj
Next i


Note all variables are declared and PipeDeltaQ(i) has been calculated for in Col8.
I know you will help me it has been delaying me for weeks now. If somebody need the whole code I will send it to your email address.
Thanks in serious Anticipation

04-06-2007 at 05:48 PM
View Profile Send Email to User Show All Posts | Quote Reply
yronium
Level: Moderator


Registered: 14-04-2002
Posts: 907
icon Re: Pls, Help me with msflexgrid comparison of 2 columns!

Hello. I don't want you feel abandoned at your own, but sincerely I have not clear what your goal is, and I felt the same when you posted the first time.

It's not clear what criteria you use to make your computes, and what sequence you are intended to follow for grid values scan. And is not clear if you are intended to set the condition (I guess a boolean flag) once, or once in every row.

I'm aware is not much, but you should try to explain us a little clearer and wider.
We're waiting around here.

____________________________
Real Programmer can count up to 1024 on his fingers

05-06-2007 at 12:19 PM
View Profile Send Email to User Show All Posts | Quote Reply
OLUPHEMMY
Level: Whizz Kid

Registered: 22-05-2007
Posts: 15
icon Re: Pls, Help me with msflexgrid comparison of 2 columns!

Thanks,
I am using msflexgrid of about 10 columns in the project, I designed it to input  values depeding on the number of pipes available in the analysis which represent each row. I have got the calculation to a stage but to get the final result I need to obey a condition. this condition is if column 1 called (nodeFrom) value is equal to column2 called (NodeTo)value AND column2 called (NodeTo)value is equal column 1 called (nodeFrom) value Then
The last result in column 8 should equal to zero(0) in column 9 except for the rows where the value of column1 and column2 interchanges as earlier shown in my explanation. e.g. column1 value =1 and column2=2 in row1 but in row4 the value of column1 =2 and column2=1
Therefore, This condition will now work on the result of column 8. The value of row1 in column8 will now be the value of row4 with opposite sign(- or +) while the value of row4 in column8 will be that of row1 also with opposite in sign(- or +)
This result of this will now be displayed in column9 as shown
in my earlier explanation.


I will attach my codes if there is any correction please help me out.

Function InterchangeColumnFigures(idx As Integer) As Boolean
Dim Sob As Integer
Dim i As Integer

For Sob = 1 To HowBig
If Sob <> idx And NodeFrom(idx) = NodeTo(Sob) And NodeFrom(Sob) = NodeTo(idx) Then
InterchangeColumnFigures = True
    End If
    Next Sob
    InterchangeColumnFigures = False
    
End Function
Public Sub CalculateFlowChange(HowBig As Integer, NumLoops As Integer)
Dim i As Integer, j As Integer
ReDim HLoopTotal(1 To NumLoops) As Single
ReDim HQLoopTotal(1 To NumLoops) As Single
ReDim PipeDeltaQ(1 To HowBig) As Double
    For i = 1 To NumLoops
        HLoopTotal(i) = 0
        HQLoopTotal(i) = 0
    Next i
    
    For i = 1 To HowBig
        HLoopTotal(Grid.TextMatrix(i, 7)) = HLoopTotal(Grid.TextMatrix(i, 7)) + HeadLoss(i)
        HQLoopTotal(Grid.TextMatrix(i, 7)) = HQLoopTotal(Grid.TextMatrix(i, 7)) + HQLoss(i)
    Next i
    For i = 1 To NumLoops
        LoopDeltaQ(i) = -HLoopTotal(i) / (2 * HQLoopTotal(i))
        
    Next i
    For i = 1 To HowBig
        PipeDeltaQ(i) = LoopDeltaQ(Grid.TextMatrix(i, 7))
        Grid.TextMatrix(i, 9) = PipeDeltaQ(i)
        Next i
    
      For i = 1 To HowBig
        For j = 1 To HowBig
      If InterchangeColumnFigures(i) Then
         PipeDeltaQ(j) = Grid.TextMatrix(i, 9) - LoopDeltaQ(Grid.TextMatrix(i, 7))
        
      End If
       Grid.TextMatrix(i, 10) = PipeDeltaQ(j)
      Next j
      Next i
      
End Sub

But this code is not giving the required valu in column9 but is giving the one value in all the rows

05-06-2007 at 04:44 PM
View Profile Send Email to User Show All Posts | Quote Reply
yronium
Level: Moderator


Registered: 14-04-2002
Posts: 907
icon Re: Pls, Help me with msflexgrid comparison of 2 columns!

Hello. Not yet time to look at your code.

quote:
OLUPHEMMY wrote:this condition is if column 1 called (nodeFrom) value is equal to column2 called (NodeTo)value AND column2 called (NodeTo)value is equal column 1 called (nodeFrom) value Then
This AND statement makes no sense: "If a = b AND b = a Then ...". Even in math ther is a postulate (I don't remember its name anymore) that says "... if a = b then we argue that b has to be equal to a." So the AND operator is useless in his point.

It's not clear if you want to compare the whole column or a single cell of it, and there are some other not so clear points, like the order of comparison (you spoke about the 4 and 8 pipes, and the result has to be stored in column 9, but why 4 vs. 8 and not, say, 4 vs. 6 or 7? And why you chose the column 9 to write in?), but we'll talk about them later. Please clarify this points first.



____________________________
Real Programmer can count up to 1024 on his fingers
05-06-2007 at 07:11 PM
View Profile Send Email to User Show All Posts | Quote Reply
OLUPHEMMY
Level: Whizz Kid

Registered: 22-05-2007
Posts: 15
icon Re: Pls, Help me with msflexgrid comparison of 2 columns!

Thanks,
I am comparing the values in column1 and column2 only with the condition stated earlier but the result of the comparison will be written to column9.
The order of comparison is from the first row to the last depending on the no of pipes in the analysis denoted in the program as (HowBig), this will be inputed by the user.
Don't be confused by the pipe thing, the program is to analyse pipe network.
The reason for choosing column9 is bcos other columns from 0-8 is filled with input & result of the previous analysis. Note I'm using msflexgrid as the table for the program with 10 columns and 50 rows.
Also be aware that am using array for the analysis.
Thanks in anticipation.

06-06-2007 at 09:40 AM
View Profile Send Email to User Show All Posts | Quote Reply
yronium
Level: Moderator


Registered: 14-04-2002
Posts: 907
icon Re: Pls, Help me with msflexgrid comparison of 2 columns!

quote:
OLUPHEMMY wrote:I am comparing the values in column1 and column2 only with the condition stated earlier
Do you mean: " ... If condition = True Then Compare_Columns Else DoNothing..."?
Or do you mean "... If column1 = condition Or/And column2 = condition Then..."


quote:
OLUPHEMMY wrote:The order of comparison is from the first row to the last
Does it mean "... If A1 = B1 Or/And A2 = B2 Or/And .... An = Bn Then ..."?
Or rather "... If AnyInTheFirstCol = AnyInSecondCol Then TakeTheFirstMatching..."?


quote:
depending on the no of pipes in the analysis denoted in the program
... "... Check The Whole Two Cols As Many Times As Pipes Number...."?
Or maybe "... Check As Many Cells As The Pipes Number..."?


quote:
columns from 0-8 is filled with input & result of the previous analysis.
OK, but you spoke about column 4 and 8, so I ask: is there any criteria for having chosen 4 and 8, or could it be some else?


Notice this kind of approach is called Pseudo-code, and after you separated all the questions and identified all the cases the algorithm is done, and you got only to translate it in VB.

____________________________
Real Programmer can count up to 1024 on his fingers
06-06-2007 at 11:05 AM
View Profile Send Email to User Show All Posts | Quote Reply
OLUPHEMMY
Level: Whizz Kid

Registered: 22-05-2007
Posts: 15
icon Re: Pls, Help me with msflexgrid comparison of 2 columns!

OK,
I will take my time to explain it one after the other,

quote:
Do you mean: " ... If condition = True Then Compare_Columns Else DoNothing..."?
Or do you mean "... If column1 = condition Or/And column2 = condition Then..."

What I mean is that in the array from row1 to the last if any cell in column1=any cell in column2 AND on the same row the cell value of column2 = cell value of column1 i.e.
col1,..........col2
1.................2
2.................5*
5.................6
6.................1
2.................3
3.................4
4.................5
5.................2*
As you can see in this analysis it only row2 and row8 that will be affected. i.e. if there is interchange of the same integer on any column the condition must be followed other wise the result of other rows=0

quote:
depending on the no of pipes in the analysis denoted in the program

What I mean is that each row represent a pipe then it should
quote:
"... Check The Whole Two Cols As Many Times As v Number of pipe(rows) indicated by the user...."?


About columns what is important is that I want the result of the comparison to be displayed in column9 and this is done using the result in column8.
i.e. if the condition of interchange is encountered in any row of col1 & col2 once or as many as the case may. e.g.  using the analysis above row2 & row8, the value of col8 of row2 will now be the value of  row8 in col9 while the value of col8 of row8 will now be the value of row2 in col9 with a change in sign in both cases (-/+). for instance,
col8.......col9
0.2.... ....0
0.4.......-0.8*
0.3........0
0.6........0
0.1........0
0.7........0
0.9........0
0.8........-0.4*

OR
col8.......col9
0.2.... ....0
-0.4.......0.8*
0.3........0
0.6........0
0.1........0
0.7........0
0.9........0
-0.8........0.4*
In my effort I have gotten all correct value for col8 but problem now lies on the correct result for col9 as shown here.
That is why I said you should check my codes if something is missing in my code.
I'm trying my best to explain this problem to you but I pray you should be able to get it this time.
Thanks for your concern
06-06-2007 at 02:25 PM
View Profile Send Email to User Show All Posts | Quote Reply
yronium
Level: Moderator


Registered: 14-04-2002
Posts: 907
icon Re: Pls, Help me with msflexgrid comparison of 2 columns!

No, sorry, it is not clear yet. In fact, you repeated what you wrote in your first post, but the unclear points are still there.

quote:
OLUPHEMMY wrote:What I mean is that in the array from row1 to the last if any cell in column1=any cell in column2 AND on the same row the cell value of column2 = cell value of column1
This is NOT what happens into your sample.
You wrote "...if any cell in column1=any cell in column2 ...", so I start looping from the cell with the number 1, under the col1 header, and find at once it's equal to the number 1 in col2's fourth row. Why don't you stop now?
You say also "...AND on the same row the cell value of column2 = cell value of column1 ...", so this could explain that you don't stop on the number 1, but it does not explain why the couple 2-5 on second row is OK: they are not "...on the same row the cell value of column2 = cell value of column1 ....", as on the same row of the 2 there is a 5! (You can check it on your own grid)
quote:
col1,..........col2
1.................2
2.................5*
5.................6
6.................1
2.................3
3.................4
4.................5
5.................2*


And yet, it's not clear why the two couples 2-5 and 5-2 are related: are you intended to search for couples with the same digits? Or is the row position relevant as well?

Once you solved this, it doesn't matter where you'll store the values you've found, so I can write it into (... the same row? - one of the two rows of?...) the ninth column. And I don't want investigate the formula the values in the eight column are computed with: it's not relevant. But you didn't explain clearly yet what comparison sequence/order/criteria you are intended to use.

I really would be glad to help you, but you got to try hard explaining us clearly what you have to do. If you are not able to, I'm afraid nobody could help you anyway.

____________________________
Real Programmer can count up to 1024 on his fingers
06-06-2007 at 07:00 PM
View Profile Send Email to User Show All Posts | Quote Reply
OLUPHEMMY
Level: Whizz Kid

Registered: 22-05-2007
Posts: 15
icon Re: Pls, Help me with msflexgrid comparison of 2 columns!

Ok,
I'm trying my best to explain to the best of my ability, as you said all i'm saying is that

quote:
In columns 1 & 2  i'm only searching for couples with the same digits as in the case of 2 & 5 and 5 & 2. This can be any digit  not restricted only to 2&5

Furthermore, the row position is not relevant this can be encountered in any row as the case may be.
My comparison of col1 to col2 is only when the digits in col1 interchanges with that of col2 and vice versa on the same row. e.g. in rows2 of the example 2 & 5 interchanges with row8 5 & 2. Therefore, this will lead to an interchange of their value in col8 with sign. This can be experienced as many as possible depending on the size of the analysis. While in other rows where their is no couple with the same digits the value of col8 remain zero(0) i.e. (col8 value -col8 value=0)
All I need is how do I compare this couple or couples in case there is in an analysis. How do I code it to fulfil this condition. the one I used is not giving me the correct result dont bother about where to store or display it just help me with the correct conditional statement for this couple of row(s) with this similarity.
07-06-2007 at 11:52 AM
View Profile Send Email to User Show All Posts | Quote Reply
yronium
Level: Moderator


Registered: 14-04-2002
Posts: 907
icon Re: Pls, Help me with msflexgrid comparison of 2 columns!

Okay, let's try to get our hands dirty:
Private Sub CompareCouples()
    Dim r As Long. r1 As Long
    Dim num1 As Double, num2 As Double
    ' assumes the grid has one fixed row
    With flxMyFlex
        For r = 1 To .Rows -1
            num1 = .TextMatrix(r, 1)
            num2 = .TextMatrix(r, 2)
            If r = .Rows - 1 Then Exit For
            For r1 = r + 1 To .Rows -1
                If (.TextMatrix(r1, 1) = num1 _
                    And TextMatrix(r1, 2) = num2) Then
                    ' we've found again the same couple, then we fill the cell
                    ' in the eighth column
                    .TextMatrix(r, 8) = put_the_calculated_value_here
                    ' remove the next Exit For instruction if you want to manage more
                    ' than two occurrences of the couple of numbers in the grid
                    Exit For
                ElseIf (.TextMatrix(r1, 1) = num2 _
                    And TextMatrix(r1, 2) = num1) Then
                    ' we've found the same couple, in reverse order, so we fill the cell
                    ' in the eighth column
                    .TextMatrix(r, 8) = put_the_calculated_value_here
                    ' remove the next Exit For instruction if you want to manage more
                    ' than two occurrences of the couple of numbers in the grid
                    Exit For
                Else            ' the two numbers are not the same
                    ' the cell in the eighth column is filled with a zero
                    .TextMatrix(r, 8) = 0
                End If
            Next r1
        Next r
    End With
End Sub

Try this approach. I didn't test it, as I don't have VB on this machine, but it should work. You can modify it by yourself in order to write the calculated values in column 8. You can also add the code to write in the column 9 cells as well.

Hope it helps

____________________________
Real Programmer can count up to 1024 on his fingers

07-06-2007 at 05:38 PM
View Profile Send Email to User Show All Posts | Quote Reply
OLUPHEMMY
Level: Whizz Kid

Registered: 22-05-2007
Posts: 15
icon Re: Pls, Help me with msflexgrid comparison of 2 columns!

Thanks for your effort
This statement generated compiler error
With flxMyFlex
If I remove it will affect the result or what do I do to make it run.
I tried to remove it but the answer I got was not the required.
in case there is a couple such as
            col1.......col2........col8...............Col9
row1       3..........4...........0.1...............0.2
row2       1..........2...........0.6................0
row3       5..........7...........0.3..............-0.4
row4         4..........3...........-0.2.............-0.1
row5       7..........5...........0.4...............-0.3
row6       7..........4...........0.5................0
row1 value in col8 will exchange with row4 value in col8 and the same thing will happen to row3 and row5 as they will exchange thier  values in col8. The exchange value will then be wriitten in Col9 while in a case where there is no couple the col9 value will be 0. As I have told you b4 I have gotten it to the result in Col8 my real probs is comparing col1 to col2 using couple of nums that interchanges and then the result of their row with the other couple.
As you can observe from my illustration above the rows underline are the one thier col9 interchanges while the rows bold also interchanges thier col9 value with changes in sign in both cases.
I understand your code but is not doing the comparison

08-06-2007 at 01:14 PM
View Profile Send Email to User Show All Posts | Quote Reply
yronium
Level: Moderator


Registered: 14-04-2002
Posts: 907
icon Re: Pls, Help me with msflexgrid comparison of 2 columns!

Ok, let's get one step at a time.

quote:
OLUPHEMMY wrote:This statement generated compiler error
With flxMyFlex
Of course it does: your grid has not this name. I posted a sample code that you got to customize with your objects: you got to replace the name I gave it ("flxMyFlex") with the name you gave to your grid (I seem to remember you named it "Grid"). Don't remove this line, or you got to put the name of your grid before each property in the block.



quote:
OLUPHEMMY wrote:in case there is a couple such as
            col1.......col2........col8...............Col9
row1       3..........4...........0.1...............0.2
row2       1..........2...........0.6................0
row3       5..........7...........0.3..............-0.4
row4         4..........3...........-0.2.............-0.1
row5       7..........5...........0.4...............-0.3
row6       7..........4...........0.5................0
row1 value in col8 will exchange with row4 value in col8 and the same thing will happen to row3 and row5 as they will exchange thier  values in col8. The exchange value will then be wriitten in Col9 while in a case where there is no couple the col9 value will be 0.
Please notice that my code doesn't affect the computation of the values to be written in col8 and col9. Instead, it tells separately the two cases when it finds the same couple or the switched couple, so you can decide to write a value in col8 in the first case and write it in col9 in the other case, and vice-versa for the second calculated value.
I didn't matter the calculation formula at all, but you can: you calculate the a and b values, then write them in col8 and col9, or in col9 and col8 according to the cases you found the couple in the grid.

Hope it helps.


____________________________
Real Programmer can count up to 1024 on his fingers
08-06-2007 at 01:47 PM
View Profile Send Email to User Show All Posts | Quote Reply
OLUPHEMMY
Level: Whizz Kid

Registered: 22-05-2007
Posts: 15
icon Re: Pls, Help me with msflexgrid comparison of 2 columns!

I am enjoying your code. Pls, I only need for switch couple in col1 and col2 only. Then if it is true that there is a switch or more  like (3&4) and (4&3) a couple, (5&7 )and (7&5) another switch couple, the corresponding value of d row (3&4) in col8 will interchange with the corresponding value of d row (4&3) in col8 with a change in sign but this will be displayed in col9; while all other rows without switch couple their value in col9 will be zero(0).

Note: I told you that I have  resolved col8 already all I want is how to interchange rows values col8  in line with rows that have switch couple(s)  and displayed this interchange in col9 while other rows without switch couple are 0.
Take your time and look at my last illustration the reason why i put col8 is for you to know that the condition of switch couple is will be acting on value already in col8 to give another result to be displayed in col9.

quote:
Dont worry about col8 the values are ready help me interchange them so as to display it in col9 following switch couple condition of col1 & col2.
08-06-2007 at 06:01 PM
View Profile Send Email to User Show All Posts | Quote Reply
OLUPHEMMY
Level: Whizz Kid

Registered: 22-05-2007
Posts: 15
icon Re: Pls, Help me with msflexgrid comparison of 2 columns!

I am enjoying your code. Pls, I only need for switch couple in col1 and col2 only. Then if it is true that there is a switch or more  like (3&4) and (4&3) a couple, (5&7 )and (7&5) another switch couple, the corresponding value of d row (3&4) in col8 will interchange with the corresponding value of d row (4&3) in col8 with a change in sign but this will be displayed in col9; while all other rows without switch couple their value in col9 will be zero(0).

Note: I told you that I have  resolved col8 already all I want is how to interchange rows values col8  in line with rows that have switch couple(s)  and displayed this interchange in col9 while other rows without switch couple are 0.
Take your time and look at my last illustration the reason why i put col8 is for you to know that the condition of switch couple is will be acting on value already in col8 to give another result to be displayed in col9.

quote:
Dont worry about col8 the values are ready help me interchange them so as to display it in col9 following switch couple condition of col1 & col2.
08-06-2007 at 06:01 PM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : VB General : Pls, Help me with msflexgrid comparison of 2 columns!
Previous Topic (My VB6 program does not cooperate with a newer version of Access)Next Topic (MILAGE CALCULATOR) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder