What's wrong with this code ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MiziaQ
    New Member
    • Nov 2007
    • 63

    What's wrong with this code ?

    I would like to delete empty rows from an msflexgrid table. I am using this loop, but it does not seem to be working ? What can I change ? Thanks in advance :)


    [CODE=vb]i = 0

    Do While i < MSFlexGrid1.Row s

    If MSFlexGrid1.Tex tMatrix(i, 0) = "" Then

    MSFlexGrid1.Rem oveItem i

    End If

    i = i + 1

    Loop[/CODE]
    Last edited by Killer42; Mar 18 '08, 11:31 PM. Reason: Added CODe=vb tag
  • QVeen72
    Recognized Expert Top Contributor
    • Oct 2006
    • 1445

    #2
    Hi,

    Reverse the Condition.. as you keep on removing the row,
    Rows Keep on decreasing, and you may end up in Runtime error..
    Check This :

    [code=vb]
    For i = MSFlexGrid1.Row s to 1 Step -1
    If Trim(MSFlexGrid 1.TextMatrix(i, 0)) = "" Then
    If MSFlexGrid1.Row s =2 Then
    MSFlexGrid1.Row s = 1
    Else
    MSFlexGrid1.Rem oveItem i
    End If
    If MSFlexGrid1.Row s <= 1 Then Exit For
    End If
    Next
    [/code]

    Regards
    Veena

    Comment

    • MiziaQ
      New Member
      • Nov 2007
      • 63

      #3
      Many thanks for your help. I tried the code,
      but get a 'subscript out of range' error (381) on the line

      If Trim(MSFlexGrid 1.TextMatrix(i, 0)) = "" Then

      Comment

      • QVeen72
        Recognized Expert Top Contributor
        • Oct 2006
        • 1445

        #4
        Hi,

        Did you change Do loop to For Loop..
        Try My Code Exactly..
        or
        Post your changed code here..

        Regards
        Veena

        Comment

        • anuragshrivastava64
          New Member
          • Jan 2007
          • 66

          #5
          Originally posted by MiziaQ
          Many thanks for your help. I tried the code,
          but get a 'subscript out of range' error (381) on the line

          If Trim(MSFlexGrid 1.TextMatrix(i, 0)) = "" Then
          May be problem is that you have initialised i from 0

          Try This
          Do While i < MSFlexGrid1.Row s - 1

          Comment

          • QVeen72
            Recognized Expert Top Contributor
            • Oct 2006
            • 1445

            #6
            Hi,

            Sorry, Change the For loop condition:

            For i = (MSFlexGrid1.Ro ws -1) to 1 Step -1

            Regards
            Veena

            Comment

            • MiziaQ
              New Member
              • Nov 2007
              • 63

              #7
              Hey, works great :)

              You've helped me a few times before, I appreciate that !

              Comment

              Working...