|
-
Feb 14th, 2003, 12:30 PM
#1
Thread Starter
New Member
Resolved: converting flexgrid text
I am trying to convert the text in a flexgrid to an integer so i can test it against a condition.
Basically, i want any cell in Col(1) with a value >=2 to be coloured red. I think the looping construct is ok as it worked fine when i changed the colour based on the text value so i must be doing something wrong with my conversion function.
can anyone help?
For i = 1 To fgMonthA3rd.Rows - 1
fgMonthA3rd.Row = i
For j = 1 To fgMonthA3rd.Cols - 1
fgMonthA3rd.Col = j
Do
'Absences is a string
Absences = fgMonthA3rd.Text
'NumAbs is an Integer
NumAbs = CInt(Absences)
If NumAbs >= 2 Then
fgMonthA3rd.CellBackColor = vbRed
End If
Loop Until fgMonthA3rd.Cols <> 1
Next j
Next i
Last edited by dcahill; Mar 5th, 2003 at 07:35 AM.
-
Feb 14th, 2003, 01:26 PM
#2
There is no reason to loop on the number of columns. Based on your posted code you are only modifying the Cell in column 1.
Your Do Loop will never end because the current column is always 1. Why are you even using a Do Loop?
Another possible error that I can see is that if the grid cell is an empty string then the line NumAbs = CInt(Absences)
will fail with a type mismatch error.
VB Code:
With fgMonthA3rd
.Redraw = False
.Col = 1
For i = 1 To .Rows - 1
Absences = .TextMatrix(i,1)
NumAbs = CInt("0" & Absences)
'Or even NumAbs = CInt("0" & .TextMatrix(i,1)) and remove the Absences = .TextMatrix(i,1) statement
If NumAbs >= 2 Then
.Row = i
.CellBackColor = vbRed
End If
Next
.Redraw = True
End With
Sorry, I did not have time to test this code but it should work.
-
Feb 17th, 2003, 09:56 AM
#3
Thread Starter
New Member
Thanks for that, it works fine.
I wasn't checking for an empty string because the content of the flexgrid iS based on the results of a database query which won't return any empty string.
I was just giving the Do Loop a shot, you were dead right about that.
Thanks again
Dave
Last edited by dcahill; Feb 17th, 2003 at 10:19 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|