Results 1 to 3 of 3

Thread: Resolved: converting flexgrid text

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2003
    Posts
    6

    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.

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    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:
    1. With fgMonthA3rd
    2.     .Redraw = False
    3.     .Col = 1
    4.  
    5.     For i = 1 To .Rows - 1
    6.  
    7.         Absences = .TextMatrix(i,1)
    8.         NumAbs = CInt("0" & Absences)  
    9.  
    10.         'Or even NumAbs = CInt("0" & .TextMatrix(i,1))  and remove the Absences = .TextMatrix(i,1) statement
    11.  
    12.  
    13.         If NumAbs >= 2 Then
    14.            .Row = i
    15.            .CellBackColor = vbRed
    16.         End If
    17.  
    18.     Next
    19.     .Redraw = True
    20. End With
    Sorry, I did not have time to test this code but it should work.

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2003
    Posts
    6
    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
  •  



Click Here to Expand Forum to Full Width