 |
|
 |
OLUPHEMMY Level: Whizz Kid
 Registered: 22-05-2007 Posts: 15
|
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 |
|
|
OLUPHEMMY Level: Whizz Kid
 Registered: 22-05-2007 Posts: 15
|
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 |
|
|
OLUPHEMMY Level: Whizz Kid
 Registered: 22-05-2007 Posts: 15
|
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 |
|
|
yronium Level: Moderator

 Registered: 14-04-2002 Posts: 907
|
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 |
|
|
OLUPHEMMY Level: Whizz Kid
 Registered: 22-05-2007 Posts: 15
|
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 |
|
|
yronium Level: Moderator

 Registered: 14-04-2002 Posts: 907
|
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 |
|
|
OLUPHEMMY Level: Whizz Kid
 Registered: 22-05-2007 Posts: 15
|
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 |
|
|
OLUPHEMMY Level: Whizz Kid
 Registered: 22-05-2007 Posts: 15
|
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 |
|
|
OLUPHEMMY Level: Whizz Kid
 Registered: 22-05-2007 Posts: 15
|
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 |
|
|
|
|
 |
 |