Home All Groups Group Topic Archive Search About

Really stupid looping problem

Author
7 Jul 2006 1:27 AM
Steven Smith
Hi everyone,

This code makes sense to me, but when I run it, it says "Loop Without Do".
Any Suggestions?

Thanks,
Steven Smith


Dim FirstPaymentDate As Date
Dim CurrRowValue As Single
Dim NumStudentsInFlex2 As Single
NumStudentsInFlex2 = MSHFlexGrid2.Rows
CurrRowVal = 1
Do While CurrRowVal < NumStudentsInFlex2   'While counter is less than number of rows in all students grid
YesDate = 0
MSHFlexGrid2.Row = CurrRowVal
        'MsgBox CurrRowVal & "(" & MSHFlexGrid2.Row & ")" & " / " & MSHFlexGrid2.Rows & " " & MSHFlexGrid2.TextMatrix(MSHFlexGrid2.Row, 0)
        If MSHFlexGrid2.TextMatrix(CurrRowVal, 2) = Date Then
            MSHFlexGrid1.AddItem (MSHFlexGrid2.TextMatrix(MSHFlexGrid2.Row, 0)) & vbTab & "First Bill"
            CurrRowVal = CurrRowVal + 1
            Loop
            End If
        If MSHFlexGrid2.TextMatrix(CurrRowVal, 3) = Date Then
            MSHFlexGrid1.AddItem (MSHFlexGrid2.TextMatrix(MSHFlexGrid2.Row, 0)) & vbTab & "Last Bill"
            CurrRowVal = CurrRowVal + 1
            Loop
            End If
        FirstPaymentDate = MSHFlexGrid2.TextMatrix(MSHFlexGrid2.Row, 2)
            YesDate = 0
            If Format(Date, "MM/DD/YYYY") = Format(DateAdd("m", 1, FirstPaymentDate), "MM/DD/YYYY") Then YesDate = 1
            If Format(Date, "MM/DD/YYYY") = Format(DateAdd("m", 2, FirstPaymentDate), "MM/DD/YYYY") Then YesDate = 1
            If Format(Date, "MM/DD/YYYY") = Format(DateAdd("m", 3, FirstPaymentDate), "MM/DD/YYYY") Then YesDate = 1
            If Format(Date, "MM/DD/YYYY") = Format(DateAdd("m", 4, FirstPaymentDate), "MM/DD/YYYY") Then YesDate = 1
            If Format(Date, "MM/DD/YYYY") = Format(DateAdd("m", 5, FirstPaymentDate), "MM/DD/YYYY") Then YesDate = 1
            If Format(Date, "MM/DD/YYYY") = Format(DateAdd("m", 6, FirstPaymentDate), "MM/DD/YYYY") Then YesDate = 1
            If Format(Date, "MM/DD/YYYY") = Format(DateAdd("m", 7, FirstPaymentDate), "MM/DD/YYYY") Then YesDate = 1
            If Format(Date, "MM/DD/YYYY") = Format(DateAdd("m", 8, FirstPaymentDate), "MM/DD/YYYY") Then YesDate = 1
            If Format(Date, "MM/DD/YYYY") = Format(DateAdd("m", 9, FirstPaymentDate), "MM/DD/YYYY") Then YesDate = 1
            If YesDate = 1 Then MSHFlexGrid1.AddItem (MSHFlexGrid2.TextMatrix(MSHFlexGrid2.Row, 0)) & vbTab & "Interval Bill"
CurrRowVal = CurrRowVal + 1
Loop

Author
7 Jul 2006 2:28 AM
Scott M.
The "Loop" keyword can not be in a conditional statement, like an IF.  If
you are using 2005, use the continue statement.


Show quoteHide quote
"Steven Smith" <slu***@webbox.com> wrote in message
news:XLirg.46037$W97.35032@twister.nyroc.rr.com...
> Hi everyone,
>
> This code makes sense to me, but when I run it, it says "Loop Without Do".
> Any Suggestions?
>
> Thanks,
> Steven Smith
>
>
> Dim FirstPaymentDate As Date
> Dim CurrRowValue As Single
> Dim NumStudentsInFlex2 As Single
> NumStudentsInFlex2 = MSHFlexGrid2.Rows
> CurrRowVal = 1
> Do While CurrRowVal < NumStudentsInFlex2   'While counter is less than
> number of rows in all students grid
> YesDate = 0
> MSHFlexGrid2.Row = CurrRowVal
>        'MsgBox CurrRowVal & "(" & MSHFlexGrid2.Row & ")" & " / " &
> MSHFlexGrid2.Rows & " " & MSHFlexGrid2.TextMatrix(MSHFlexGrid2.Row, 0)
>        If MSHFlexGrid2.TextMatrix(CurrRowVal, 2) = Date Then
>            MSHFlexGrid1.AddItem (MSHFlexGrid2.TextMatrix(MSHFlexGrid2.Row,
> 0)) & vbTab & "First Bill"
>            CurrRowVal = CurrRowVal + 1
>            Loop
>            End If
>        If MSHFlexGrid2.TextMatrix(CurrRowVal, 3) = Date Then
>            MSHFlexGrid1.AddItem (MSHFlexGrid2.TextMatrix(MSHFlexGrid2.Row,
> 0)) & vbTab & "Last Bill"
>            CurrRowVal = CurrRowVal + 1
>            Loop
>            End If
>        FirstPaymentDate = MSHFlexGrid2.TextMatrix(MSHFlexGrid2.Row, 2)
>            YesDate = 0
>            If Format(Date, "MM/DD/YYYY") = Format(DateAdd("m", 1,
> FirstPaymentDate), "MM/DD/YYYY") Then YesDate = 1
>            If Format(Date, "MM/DD/YYYY") = Format(DateAdd("m", 2,
> FirstPaymentDate), "MM/DD/YYYY") Then YesDate = 1
>            If Format(Date, "MM/DD/YYYY") = Format(DateAdd("m", 3,
> FirstPaymentDate), "MM/DD/YYYY") Then YesDate = 1
>            If Format(Date, "MM/DD/YYYY") = Format(DateAdd("m", 4,
> FirstPaymentDate), "MM/DD/YYYY") Then YesDate = 1
>            If Format(Date, "MM/DD/YYYY") = Format(DateAdd("m", 5,
> FirstPaymentDate), "MM/DD/YYYY") Then YesDate = 1
>            If Format(Date, "MM/DD/YYYY") = Format(DateAdd("m", 6,
> FirstPaymentDate), "MM/DD/YYYY") Then YesDate = 1
>            If Format(Date, "MM/DD/YYYY") = Format(DateAdd("m", 7,
> FirstPaymentDate), "MM/DD/YYYY") Then YesDate = 1
>            If Format(Date, "MM/DD/YYYY") = Format(DateAdd("m", 8,
> FirstPaymentDate), "MM/DD/YYYY") Then YesDate = 1
>            If Format(Date, "MM/DD/YYYY") = Format(DateAdd("m", 9,
> FirstPaymentDate), "MM/DD/YYYY") Then YesDate = 1
>            If YesDate = 1 Then MSHFlexGrid1.AddItem
> (MSHFlexGrid2.TextMatrix(MSHFlexGrid2.Row, 0)) & vbTab & "Interval Bill"
> CurrRowVal = CurrRowVal + 1
> Loop
Author
7 Jul 2006 8:10 AM
Jan Hyde
Steven Smith <slu***@webbox.com>'s wild thoughts were
released on Fri, 07 Jul 2006 01:27:19 GMT bearing the
following fruit:

>Hi everyone,
>
>This code makes sense to me, but when I run it, it says "Loop Without Do".
>Any Suggestions?
>
>Thanks,
>Steven Smith
>
>
I'm guessing the following is what your trying to achieve.

Dim FirstPaymentDate As Date
Dim CurrRowValue As Single
Dim NumStudentsInFlex2 As Single

  NumStudentsInFlex2 = MSHFlexGrid2.Rows
  CurrRowVal = 1
  Do While CurrRowVal < NumStudentsInFlex2   'While counter
is less than number of rows in all students grid

    YesDate = 0
    MSHFlexGrid2.Row = CurrRowVal
    If MSHFlexGrid2.TextMatrix(CurrRowVal, 2) = Date Then
            MSHFlexGrid1.AddItem
(MSHFlexGrid2.TextMatrix(MSHFlexGrid2.Row, 0)) & vbTab &
"First Bill"
            CurrRowVal = CurrRowVal + 1
     ElseIf MSHFlexGrid2.TextMatrix(CurrRowVal, 3) = Date
Then
            MSHFlexGrid1.AddItem
(MSHFlexGrid2.TextMatrix(MSHFlexGrid2.Row, 0)) & vbTab &
"Last Bill"
            CurrRowVal = CurrRowVal + 1
    Else
            FirstPaymentDate =
MSHFlexGrid2.TextMatrix(MSHFlexGrid2.Row, 2)
            YesDate = 0
            If Format(Date, "MM/DD/YYYY") =
Format(DateAdd("m", 1, FirstPaymentDate), "MM/DD/YYYY") Then
YesDate = 1
            If Format(Date, "MM/DD/YYYY") =
Format(DateAdd("m", 2, FirstPaymentDate), "MM/DD/YYYY") Then
YesDate = 1
            If Format(Date, "MM/DD/YYYY") =
Format(DateAdd("m", 3, FirstPaymentDate), "MM/DD/YYYY") Then
YesDate = 1
            If Format(Date, "MM/DD/YYYY") =
Format(DateAdd("m", 4, FirstPaymentDate), "MM/DD/YYYY") Then
YesDate = 1
            If Format(Date, "MM/DD/YYYY") =
Format(DateAdd("m", 5, FirstPaymentDate), "MM/DD/YYYY") Then
YesDate = 1
            If Format(Date, "MM/DD/YYYY") =
Format(DateAdd("m", 6, FirstPaymentDate), "MM/DD/YYYY") Then
YesDate = 1
            If Format(Date, "MM/DD/YYYY") =
Format(DateAdd("m", 7, FirstPaymentDate), "MM/DD/YYYY") Then
YesDate = 1
            If Format(Date, "MM/DD/YYYY") =
Format(DateAdd("m", 8, FirstPaymentDate), "MM/DD/YYYY") Then
YesDate = 1
            If Format(Date, "MM/DD/YYYY") =
Format(DateAdd("m", 9, FirstPaymentDate), "MM/DD/YYYY") Then
YesDate = 1
            If YesDate = 1 Then MSHFlexGrid1.AddItem
(MSHFlexGrid2.TextMatrix(MSHFlexGrid2.Row, 0)) & vbTab &
"Interval Bill"
          CurrRowVal = CurrRowVal + 1
     End If
  Loop


Jan Hyde (VB MVP)

--
Airport: Terminal architecture for the upward mobile (M. Rose Pierce)
Author
7 Jul 2006 3:17 PM
Scott M.
Or better yet:

Dim FirstPaymentDate As Date
Dim CurrRowValue, NumStudentsInFlex2  As Single
NumStudentsInFlex2 = MSHFlexGrid2.Rows
CurrRowVal = 1
Dim BillType As String        '  <---  This is what you are really trying to
figure out after all, right?

Do While CurrRowVal < NumStudentsInFlex2   'While counter is less than # of
rows in all students grid
        MSHFlexGrid2.Row = CurrRowVal

        If MSHFlexGrid2.TextMatrix(CurrRowVal, 2) = Date Then
            BillType="First Bill"
        ElseIf MSHFlexGrid2.TextMatrix(CurrRowVal, 3) = Date Then
            BillType="Last Bill"
        Else
            FirstPaymentDate = MSHFlexGrid2.TextMatrix(MSHFlexGrid2.Row, 2)

            Dim x As Integer = 1
            For x = 1 To 9
                'You don't have to format a date to work with the month
portion of it
                If Date = DateAdd("m", x, FirstPaymentDate) Then
BillType="Interval Bill"
            Next
        End If

        'Instead of writing the same line of code 3 times with one small
difference each time,
        'just write it once and work on the real problem, which is figuring
the bill type.
        MSHFlexGrid1.AddItem (MSHFlexGrid2.TextMatrix(MSHFlexGrid2.Row, 0))
& vbTab & BillType

        'In a While loop, you want to be careful to only increase the
counter when absolutely necessary,
        'so, let's only do it here
        CurrRowVal = CurrRowVal + 1
Loop








Show quoteHide quote
"Jan Hyde" <StellaDrin***@REMOVE.ME.uboot.com> wrote in message
news:bm5sa2tia3s1slfspk8jfi5st3thu5e68d@4ax.com...
> Steven Smith <slu***@webbox.com>'s wild thoughts were
> released on Fri, 07 Jul 2006 01:27:19 GMT bearing the
> following fruit:
>
>>Hi everyone,
>>
>>This code makes sense to me, but when I run it, it says "Loop Without Do".
>>Any Suggestions?
>>
>>Thanks,
>>Steven Smith
>>
>>
> I'm guessing the following is what your trying to achieve.
>
> Dim FirstPaymentDate As Date
> Dim CurrRowValue As Single
> Dim NumStudentsInFlex2 As Single
>
>  NumStudentsInFlex2 = MSHFlexGrid2.Rows
>  CurrRowVal = 1
>  Do While CurrRowVal < NumStudentsInFlex2   'While counter
> is less than number of rows in all students grid
>
>    YesDate = 0
>    MSHFlexGrid2.Row = CurrRowVal
>    If MSHFlexGrid2.TextMatrix(CurrRowVal, 2) = Date Then
>            MSHFlexGrid1.AddItem
> (MSHFlexGrid2.TextMatrix(MSHFlexGrid2.Row, 0)) & vbTab &
> "First Bill"
>            CurrRowVal = CurrRowVal + 1
>     ElseIf MSHFlexGrid2.TextMatrix(CurrRowVal, 3) = Date
> Then
>            MSHFlexGrid1.AddItem
> (MSHFlexGrid2.TextMatrix(MSHFlexGrid2.Row, 0)) & vbTab &
> "Last Bill"
>            CurrRowVal = CurrRowVal + 1
>    Else
>            FirstPaymentDate =
> MSHFlexGrid2.TextMatrix(MSHFlexGrid2.Row, 2)
>            YesDate = 0
>            If Format(Date, "MM/DD/YYYY") =
> Format(DateAdd("m", 1, FirstPaymentDate), "MM/DD/YYYY") Then
> YesDate = 1
>            If Format(Date, "MM/DD/YYYY") =
> Format(DateAdd("m", 2, FirstPaymentDate), "MM/DD/YYYY") Then
> YesDate = 1
>            If Format(Date, "MM/DD/YYYY") =
> Format(DateAdd("m", 3, FirstPaymentDate), "MM/DD/YYYY") Then
> YesDate = 1
>            If Format(Date, "MM/DD/YYYY") =
> Format(DateAdd("m", 4, FirstPaymentDate), "MM/DD/YYYY") Then
> YesDate = 1
>            If Format(Date, "MM/DD/YYYY") =
> Format(DateAdd("m", 5, FirstPaymentDate), "MM/DD/YYYY") Then
> YesDate = 1
>            If Format(Date, "MM/DD/YYYY") =
> Format(DateAdd("m", 6, FirstPaymentDate), "MM/DD/YYYY") Then
> YesDate = 1
>            If Format(Date, "MM/DD/YYYY") =
> Format(DateAdd("m", 7, FirstPaymentDate), "MM/DD/YYYY") Then
> YesDate = 1
>            If Format(Date, "MM/DD/YYYY") =
> Format(DateAdd("m", 8, FirstPaymentDate), "MM/DD/YYYY") Then
> YesDate = 1
>            If Format(Date, "MM/DD/YYYY") =
> Format(DateAdd("m", 9, FirstPaymentDate), "MM/DD/YYYY") Then
> YesDate = 1
>            If YesDate = 1 Then MSHFlexGrid1.AddItem
> (MSHFlexGrid2.TextMatrix(MSHFlexGrid2.Row, 0)) & vbTab &
> "Interval Bill"
>          CurrRowVal = CurrRowVal + 1
>     End If
>  Loop
>
>
> Jan Hyde (VB MVP)
>
> --
> Airport: Terminal architecture for the upward mobile (M. Rose Pierce)
>