clarwc
asked on
Flexgrid question for cliffab
Last month you helped me insert an image into a flexgrid where the text in a particular column read "Red", "yellow", or "Green". My requirement has changed slightly and I now need to compare column 3 to column 8, column 4 to column 9, and column 5 to column 10. I don't want Column 8, 9, or 10 to show in my display and I believe I did that by setting the columns to 8. My problem is doing the compare. The code you gave me as modified is:
FG1.Font.Name = "arial"
FG1.Font.Size = "8"
FG1.Font.Bold = True
FG1.Cols = 8
S = " |<Code |<Program Title |<Cost |<Sched |<Perf |<Remarks |<Updated "
FG1.FormatString = S$
FG1.WordWrap = True
Dim nCnt1 As Long
Dim nColNum As Long
Dim sPicFile As String
For nCnt1 = 1 To FG1.Rows - 1
For nColNum = 3 To 5
Select Case FG1.TextMatrix(nCnt1, nColNum)
Case "Red"
FG1.CellPictureAlignment = flexAlignCenterCenter
sPicFile = "c:\205gui\YelRed.gif"
Case "Green"
FG1.CellPictureAlignment = flexAlignCenterCenter
sPicFile = "c:\205gui\Grnred.gif"
Case "Yellow"
FG1.CellPictureAlignment = flexAlignCenterCenter
sPicFile = "c:\205gui\Yelgrn.gif"
Case Else
sPicFile = ""
End Select
If sPicFile <> "" Then
FG1.Col = nColNum
FG1.Row = nCnt1
Set FG1.CellPicture = LoadPicture(sPicFile)
FG1.TextMatrix(nCnt1, nColNum) = ""
End If
Next nColNum
Next nCnt1
Call fixflex
End Sub
Private Sub fixflex()
Dim nrow As Integer
LblCellText.Width = FG1.ColWidth(6)
For nrow = 1 To FG1.Rows - 1
LblCellText.Caption = FG1.TextMatrix(nrow, 6)
FG1.RowHeight(nrow) = LblCellText.Height + 240
Next nrow
End Sub
any idea how I can compare the data in one field with the data in another to determine which gif to display???
Specifically, I now have 9 gifs for this grid. They are grngrn, grn, yel, grnred, yelgrn, yelyel, yelred, redgrn, redyel, and redred. Comparing the field coststat_1 to Coststat_2 tells me which gif to display. I tried to insert an and statement in the code you gave me to look at the data in coststat_2 but got a datatype mismatch.
Any Ideas how to go about this???
Warren
FG1.Font.Name = "arial"
FG1.Font.Size = "8"
FG1.Font.Bold = True
FG1.Cols = 8
S = " |<Code |<Program Title |<Cost |<Sched |<Perf |<Remarks |<Updated "
FG1.FormatString = S$
FG1.WordWrap = True
Dim nCnt1 As Long
Dim nColNum As Long
Dim sPicFile As String
For nCnt1 = 1 To FG1.Rows - 1
For nColNum = 3 To 5
Select Case FG1.TextMatrix(nCnt1, nColNum)
Case "Red"
FG1.CellPictureAlignment = flexAlignCenterCenter
sPicFile = "c:\205gui\YelRed.gif"
Case "Green"
FG1.CellPictureAlignment = flexAlignCenterCenter
sPicFile = "c:\205gui\Grnred.gif"
Case "Yellow"
FG1.CellPictureAlignment = flexAlignCenterCenter
sPicFile = "c:\205gui\Yelgrn.gif"
Case Else
sPicFile = ""
End Select
If sPicFile <> "" Then
FG1.Col = nColNum
FG1.Row = nCnt1
Set FG1.CellPicture = LoadPicture(sPicFile)
FG1.TextMatrix(nCnt1, nColNum) = ""
End If
Next nColNum
Next nCnt1
Call fixflex
End Sub
Private Sub fixflex()
Dim nrow As Integer
LblCellText.Width = FG1.ColWidth(6)
For nrow = 1 To FG1.Rows - 1
LblCellText.Caption = FG1.TextMatrix(nrow, 6)
FG1.RowHeight(nrow) = LblCellText.Height + 240
Next nrow
End Sub
any idea how I can compare the data in one field with the data in another to determine which gif to display???
Specifically, I now have 9 gifs for this grid. They are grngrn, grn, yel, grnred, yelgrn, yelyel, yelred, redgrn, redyel, and redred. Comparing the field coststat_1 to Coststat_2 tells me which gif to display. I tried to insert an and statement in the code you gave me to look at the data in coststat_2 but got a datatype mismatch.
Any Ideas how to go about this???
Warren
I will take a look at this and see what's going on and get back to you.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
In the code you originally helped me with all I needed to do was replace the text "Red" with the graphic for red and so forth. Now I need to compare the contents of column 3 (Coststat_1) with Column 8 (Coststat_2), Column 4 (Schedstat_1) with Column 9 (Schedstat_2), and Column 5 (Perfstat_1) with Column 10 (Perfstat_2). The results of the comparison will determine which of 12 graphics should be displayed in column 3, 4, and 5. For example is Coststat_1 is "red" and Coststat_2 is yellow I need to display the graphic RedYel.gif in column 3.
Does that help?
Also, I didn't know better that to hard code the path. how do I let the user decide where to save the HTML file?
Does that help?
Also, I didn't know better that to hard code the path. how do I let the user decide where to save the HTML file?
In my example above, the code I gave should be what you want. I suggested placing the contents of columns 3, 4, and 5 in columns 11, 12, and 13 only as an aid in future debugging. If you really need the contents of 3, 4, and 5, then replace the follwing lines of code:
Replace:
For nColNum = 8 To 10
With:
For nColNum = 3 To 5
Replace:
Select Case FG1.TextMatrix(nCnt1, nColNum + 3)
With:
Select Case FG1.TextMatrix(nCnt1, nColNum + 5)
To let the user select which path, you can use the common dialog control. You can look up examples on how to use this control in the help file.
Replace:
For nColNum = 8 To 10
With:
For nColNum = 3 To 5
Replace:
Select Case FG1.TextMatrix(nCnt1, nColNum + 3)
With:
Select Case FG1.TextMatrix(nCnt1, nColNum + 5)
To let the user select which path, you can use the common dialog control. You can look up examples on how to use this control in the help file.
ASKER
cliffab,
Thanks for the help. I don't think I am making my problem clear. I believe what I need will be some type of if else statement. As an example for the first record something like:
If Data1.Recordset.Fields("co ststat_1") = "Red" and Data1.Recordset.Fields("co ststat_2") = "Yellow" Then
sPicFile = "c:\205gui\RedYel.gif"
else if
If Data1.Recordset.Fields("co ststat_1") = "Red" and Data1.Recordset.Fields("co ststat_2") = "Green" Then
sPicFile = "c:\205gui\Redgrn.gif"
Something like that but I don't know how to get it to co through each record and look at column 3 (which is coststat_1), then column 4 (schedstat_1), and column 5 (Perfstat_1)
Does this make better sense.
Warren
Thanks for the help. I don't think I am making my problem clear. I believe what I need will be some type of if else statement. As an example for the first record something like:
If Data1.Recordset.Fields("co
sPicFile = "c:\205gui\RedYel.gif"
else if
If Data1.Recordset.Fields("co
sPicFile = "c:\205gui\Redgrn.gif"
Something like that but I don't know how to get it to co through each record and look at column 3 (which is coststat_1), then column 4 (schedstat_1), and column 5 (Perfstat_1)
Does this make better sense.
Warren
I was under the impression that you wanted to go by the cell values, (which is what the field values are) rather than the field values themselves. You stated in your original question above that you wanted to compare the values of column 3 with the values of column 8, etc.
It works the same either way. I'm sorry but I suppose it was I who was not very clear. If you have the column 3 value (or Data1.Recordset.Fields("co ststat_1") ) of "Red" and the column 8 value (or Data1.Recordset.Fields("co ststat_2") value) of "Yellow"
then you can create a filename based on that ("Red" = "red" + "Yellow" = "yel"). This would be the most efficient way of doing what you ask. However, if you want to use a compare type of code, I will give you that.
If/Then/Else statements are very ineffecient. A Select/Case statement would be a much better idea.
Select Case Data1.Recordset.Fields("co ststat_1")
Case "Red"
Select Case Data1.Recordset.Fields("co ststat_2")
Case "Red"
sPicFile = "redred.gif"
Case "Yellow"
sPicFile = "redyel.gif"
Case "Green"
sPicFile = "redgrn.gif"
Case Else
sPicFile = "red.gif"
End Select
Case "Yellow"
Select Case Data1.Recordset.Fields("co ststat_2")
Case "Red"
sPicFile = "yelred.gif"
Case "Yellow"
sPicFile = "yelyel.gif"
Case "Green"
sPicFile = "yelgrn.gif"
Case Else
sPicFile = "yellow.gif"
End Select
Case "Green"
Select Case Data1.Recordset.Fields("co ststat_2")
Case "Red"
sPicFile = "grnred.gif"
Case "Yellow"
sPicFile = "grnyel.gif"
Case "Green"
sPicFile = "grngrn.gif"
Case Else
sPicFile = "green.gif"
End Select
End Select
sPicFile = "c:\205gui\" & sPicFile
On the other hand, an If/Then/Else statement might look like this:
If Data1.Recordset.Fields("co ststat_1") = "Red" Then
If Data1.Recordset.Fields("co ststat_2") = "Red" Then
sPicFile = "redred.gif"
ElseIf Data1.Recordset.Fields("co ststat_2") = "Yellow" Then
sPicFile = "redyel.gif"
ElseIf Data1.Recordset.Fields("co ststat_2") = "Green" Then
sPicFile = "redgrn.gif"
Else
sPicFile = "red.gif"
End If
ElseIf Data1.Recordset.Fields("co ststat_1") = "Yellow" Then
If Data1.Recordset.Fields("co ststat_2") = "Red" Then
sPicFile = "yelred.gif"
ElseIf Data1.Recordset.Fields("co ststat_2") = "Yellow" Then
sPicFile = "yelyel.gif"
ElseIf Data1.Recordset.Fields("co ststat_2") = "Green" Then
sPicFile = "yelgrn.gif"
Else
sPicFile = "yellow.gif"
End If
ElseIf Data1.Recordset.Fields("co ststat_1") = "Green" Then
If Data1.Recordset.Fields("co ststat_2") = "Red" Then
sPicFile = "grnred.gif"
ElseIf Data1.Recordset.Fields("co ststat_2") = "Yellow" Then
sPicFile = "grnyel.gif"
ElseIf Data1.Recordset.Fields("co ststat_2") = "Green" Then
sPicFile = "grngrn.gif"
Else
sPicFile = "green.gif"
End If
End If
sPicFile = "c:\205gui\" & sPicFile
It works the same either way. I'm sorry but I suppose it was I who was not very clear. If you have the column 3 value (or Data1.Recordset.Fields("co
then you can create a filename based on that ("Red" = "red" + "Yellow" = "yel"). This would be the most efficient way of doing what you ask. However, if you want to use a compare type of code, I will give you that.
If/Then/Else statements are very ineffecient. A Select/Case statement would be a much better idea.
Select Case Data1.Recordset.Fields("co
Case "Red"
Select Case Data1.Recordset.Fields("co
Case "Red"
sPicFile = "redred.gif"
Case "Yellow"
sPicFile = "redyel.gif"
Case "Green"
sPicFile = "redgrn.gif"
Case Else
sPicFile = "red.gif"
End Select
Case "Yellow"
Select Case Data1.Recordset.Fields("co
Case "Red"
sPicFile = "yelred.gif"
Case "Yellow"
sPicFile = "yelyel.gif"
Case "Green"
sPicFile = "yelgrn.gif"
Case Else
sPicFile = "yellow.gif"
End Select
Case "Green"
Select Case Data1.Recordset.Fields("co
Case "Red"
sPicFile = "grnred.gif"
Case "Yellow"
sPicFile = "grnyel.gif"
Case "Green"
sPicFile = "grngrn.gif"
Case Else
sPicFile = "green.gif"
End Select
End Select
sPicFile = "c:\205gui\" & sPicFile
On the other hand, an If/Then/Else statement might look like this:
If Data1.Recordset.Fields("co
If Data1.Recordset.Fields("co
sPicFile = "redred.gif"
ElseIf Data1.Recordset.Fields("co
sPicFile = "redyel.gif"
ElseIf Data1.Recordset.Fields("co
sPicFile = "redgrn.gif"
Else
sPicFile = "red.gif"
End If
ElseIf Data1.Recordset.Fields("co
If Data1.Recordset.Fields("co
sPicFile = "yelred.gif"
ElseIf Data1.Recordset.Fields("co
sPicFile = "yelyel.gif"
ElseIf Data1.Recordset.Fields("co
sPicFile = "yelgrn.gif"
Else
sPicFile = "yellow.gif"
End If
ElseIf Data1.Recordset.Fields("co
If Data1.Recordset.Fields("co
sPicFile = "grnred.gif"
ElseIf Data1.Recordset.Fields("co
sPicFile = "grnyel.gif"
ElseIf Data1.Recordset.Fields("co
sPicFile = "grngrn.gif"
Else
sPicFile = "green.gif"
End If
End If
sPicFile = "c:\205gui\" & sPicFile
ASKER
cliffab,
That worked!!! Thanks a lot.
That worked!!! Thanks a lot.