Really stupid looping problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steven Smith

    #1

    Really stupid looping problem

    Hi everyone,

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

    Thanks,
    Steven Smith


    Dim FirstPaymentDat e As Date
    Dim CurrRowValue As Single
    Dim NumStudentsInFl ex2 As Single
    NumStudentsInFl ex2 = MSHFlexGrid2.Ro ws
    CurrRowVal = 1
    Do While CurrRowVal < NumStudentsInFl ex2 'While counter is less than number of rows in all students grid
    YesDate = 0
    MSHFlexGrid2.Ro w = CurrRowVal
    'MsgBox CurrRowVal & "(" & MSHFlexGrid2.Ro w & ")" & " / " & MSHFlexGrid2.Ro ws & " " & MSHFlexGrid2.Te xtMatrix(MSHFle xGrid2.Row, 0)
    If MSHFlexGrid2.Te xtMatrix(CurrRo wVal, 2) = Date Then
    MSHFlexGrid1.Ad dItem (MSHFlexGrid2.T extMatrix(MSHFl exGrid2.Row, 0)) & vbTab & "First Bill"
    CurrRowVal = CurrRowVal + 1
    Loop
    End If
    If MSHFlexGrid2.Te xtMatrix(CurrRo wVal, 3) = Date Then
    MSHFlexGrid1.Ad dItem (MSHFlexGrid2.T extMatrix(MSHFl exGrid2.Row, 0)) & vbTab & "Last Bill"
    CurrRowVal = CurrRowVal + 1
    Loop
    End If
    FirstPaymentDat e = MSHFlexGrid2.Te xtMatrix(MSHFle xGrid2.Row, 2)
    YesDate = 0
    If Format(Date, "MM/DD/YYYY") = Format(DateAdd( "m", 1, FirstPaymentDat e), "MM/DD/YYYY") Then YesDate = 1
    If Format(Date, "MM/DD/YYYY") = Format(DateAdd( "m", 2, FirstPaymentDat e), "MM/DD/YYYY") Then YesDate = 1
    If Format(Date, "MM/DD/YYYY") = Format(DateAdd( "m", 3, FirstPaymentDat e), "MM/DD/YYYY") Then YesDate = 1
    If Format(Date, "MM/DD/YYYY") = Format(DateAdd( "m", 4, FirstPaymentDat e), "MM/DD/YYYY") Then YesDate = 1
    If Format(Date, "MM/DD/YYYY") = Format(DateAdd( "m", 5, FirstPaymentDat e), "MM/DD/YYYY") Then YesDate = 1
    If Format(Date, "MM/DD/YYYY") = Format(DateAdd( "m", 6, FirstPaymentDat e), "MM/DD/YYYY") Then YesDate = 1
    If Format(Date, "MM/DD/YYYY") = Format(DateAdd( "m", 7, FirstPaymentDat e), "MM/DD/YYYY") Then YesDate = 1
    If Format(Date, "MM/DD/YYYY") = Format(DateAdd( "m", 8, FirstPaymentDat e), "MM/DD/YYYY") Then YesDate = 1
    If Format(Date, "MM/DD/YYYY") = Format(DateAdd( "m", 9, FirstPaymentDat e), "MM/DD/YYYY") Then YesDate = 1
    If YesDate = 1 Then MSHFlexGrid1.Ad dItem (MSHFlexGrid2.T extMatrix(MSHFl exGrid2.Row, 0)) & vbTab & "Interval Bill"
    CurrRowVal = CurrRowVal + 1
    Loop
  • Scott M.

    #2
    Re: Really stupid looping problem

    The "Loop" keyword can not be in a conditional statement, like an IF. If
    you are using 2005, use the continue statement.


    "Steven Smith" <sluke4@webbox. comwrote in message
    news:XLirg.4603 7$W97.35032@twi ster.nyroc.rr.c om...
    Hi everyone,
    >
    This code makes sense to me, but when I run it, it says "Loop Without Do".
    Any Suggestions?
    >
    Thanks,
    Steven Smith
    >
    >
    Dim FirstPaymentDat e As Date
    Dim CurrRowValue As Single
    Dim NumStudentsInFl ex2 As Single
    NumStudentsInFl ex2 = MSHFlexGrid2.Ro ws
    CurrRowVal = 1
    Do While CurrRowVal < NumStudentsInFl ex2 'While counter is less than
    number of rows in all students grid
    YesDate = 0
    MSHFlexGrid2.Ro w = CurrRowVal
    'MsgBox CurrRowVal & "(" & MSHFlexGrid2.Ro w & ")" & " / " &
    MSHFlexGrid2.Ro ws & " " & MSHFlexGrid2.Te xtMatrix(MSHFle xGrid2.Row, 0)
    If MSHFlexGrid2.Te xtMatrix(CurrRo wVal, 2) = Date Then
    MSHFlexGrid1.Ad dItem (MSHFlexGrid2.T extMatrix(MSHFl exGrid2.Row,
    0)) & vbTab & "First Bill"
    CurrRowVal = CurrRowVal + 1
    Loop
    End If
    If MSHFlexGrid2.Te xtMatrix(CurrRo wVal, 3) = Date Then
    MSHFlexGrid1.Ad dItem (MSHFlexGrid2.T extMatrix(MSHFl exGrid2.Row,
    0)) & vbTab & "Last Bill"
    CurrRowVal = CurrRowVal + 1
    Loop
    End If
    FirstPaymentDat e = MSHFlexGrid2.Te xtMatrix(MSHFle xGrid2.Row, 2)
    YesDate = 0
    If Format(Date, "MM/DD/YYYY") = Format(DateAdd( "m", 1,
    FirstPaymentDat e), "MM/DD/YYYY") Then YesDate = 1
    If Format(Date, "MM/DD/YYYY") = Format(DateAdd( "m", 2,
    FirstPaymentDat e), "MM/DD/YYYY") Then YesDate = 1
    If Format(Date, "MM/DD/YYYY") = Format(DateAdd( "m", 3,
    FirstPaymentDat e), "MM/DD/YYYY") Then YesDate = 1
    If Format(Date, "MM/DD/YYYY") = Format(DateAdd( "m", 4,
    FirstPaymentDat e), "MM/DD/YYYY") Then YesDate = 1
    If Format(Date, "MM/DD/YYYY") = Format(DateAdd( "m", 5,
    FirstPaymentDat e), "MM/DD/YYYY") Then YesDate = 1
    If Format(Date, "MM/DD/YYYY") = Format(DateAdd( "m", 6,
    FirstPaymentDat e), "MM/DD/YYYY") Then YesDate = 1
    If Format(Date, "MM/DD/YYYY") = Format(DateAdd( "m", 7,
    FirstPaymentDat e), "MM/DD/YYYY") Then YesDate = 1
    If Format(Date, "MM/DD/YYYY") = Format(DateAdd( "m", 8,
    FirstPaymentDat e), "MM/DD/YYYY") Then YesDate = 1
    If Format(Date, "MM/DD/YYYY") = Format(DateAdd( "m", 9,
    FirstPaymentDat e), "MM/DD/YYYY") Then YesDate = 1
    If YesDate = 1 Then MSHFlexGrid1.Ad dItem
    (MSHFlexGrid2.T extMatrix(MSHFl exGrid2.Row, 0)) & vbTab & "Interval Bill"
    CurrRowVal = CurrRowVal + 1
    Loop

    Comment

    • Jan Hyde

      #3
      Re: Really stupid looping problem

      Steven Smith <sluke4@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 FirstPaymentDat e As Date
      Dim CurrRowValue As Single
      Dim NumStudentsInFl ex2 As Single

      NumStudentsInFl ex2 = MSHFlexGrid2.Ro ws
      CurrRowVal = 1
      Do While CurrRowVal < NumStudentsInFl ex2 'While counter
      is less than number of rows in all students grid

      YesDate = 0
      MSHFlexGrid2.Ro w = CurrRowVal
      If MSHFlexGrid2.Te xtMatrix(CurrRo wVal, 2) = Date Then
      MSHFlexGrid1.Ad dItem
      (MSHFlexGrid2.T extMatrix(MSHFl exGrid2.Row, 0)) & vbTab &
      "First Bill"
      CurrRowVal = CurrRowVal + 1
      ElseIf MSHFlexGrid2.Te xtMatrix(CurrRo wVal, 3) = Date
      Then
      MSHFlexGrid1.Ad dItem
      (MSHFlexGrid2.T extMatrix(MSHFl exGrid2.Row, 0)) & vbTab &
      "Last Bill"
      CurrRowVal = CurrRowVal + 1
      Else
      FirstPaymentDat e =
      MSHFlexGrid2.Te xtMatrix(MSHFle xGrid2.Row, 2)
      YesDate = 0
      If Format(Date, "MM/DD/YYYY") =
      Format(DateAdd( "m", 1, FirstPaymentDat e), "MM/DD/YYYY") Then
      YesDate = 1
      If Format(Date, "MM/DD/YYYY") =
      Format(DateAdd( "m", 2, FirstPaymentDat e), "MM/DD/YYYY") Then
      YesDate = 1
      If Format(Date, "MM/DD/YYYY") =
      Format(DateAdd( "m", 3, FirstPaymentDat e), "MM/DD/YYYY") Then
      YesDate = 1
      If Format(Date, "MM/DD/YYYY") =
      Format(DateAdd( "m", 4, FirstPaymentDat e), "MM/DD/YYYY") Then
      YesDate = 1
      If Format(Date, "MM/DD/YYYY") =
      Format(DateAdd( "m", 5, FirstPaymentDat e), "MM/DD/YYYY") Then
      YesDate = 1
      If Format(Date, "MM/DD/YYYY") =
      Format(DateAdd( "m", 6, FirstPaymentDat e), "MM/DD/YYYY") Then
      YesDate = 1
      If Format(Date, "MM/DD/YYYY") =
      Format(DateAdd( "m", 7, FirstPaymentDat e), "MM/DD/YYYY") Then
      YesDate = 1
      If Format(Date, "MM/DD/YYYY") =
      Format(DateAdd( "m", 8, FirstPaymentDat e), "MM/DD/YYYY") Then
      YesDate = 1
      If Format(Date, "MM/DD/YYYY") =
      Format(DateAdd( "m", 9, FirstPaymentDat e), "MM/DD/YYYY") Then
      YesDate = 1
      If YesDate = 1 Then MSHFlexGrid1.Ad dItem
      (MSHFlexGrid2.T extMatrix(MSHFl exGrid2.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)

      Comment

      • Scott M.

        #4
        Re: Really stupid looping problem

        Or better yet:

        Dim FirstPaymentDat e As Date
        Dim CurrRowValue, NumStudentsInFl ex2 As Single
        NumStudentsInFl ex2 = MSHFlexGrid2.Ro ws
        CurrRowVal = 1
        Dim BillType As String ' <--- This is what you are really trying to
        figure out after all, right?

        Do While CurrRowVal < NumStudentsInFl ex2 'While counter is less than # of
        rows in all students grid
        MSHFlexGrid2.Ro w = CurrRowVal

        If MSHFlexGrid2.Te xtMatrix(CurrRo wVal, 2) = Date Then
        BillType="First Bill"
        ElseIf MSHFlexGrid2.Te xtMatrix(CurrRo wVal, 3) = Date Then
        BillType="Last Bill"
        Else
        FirstPaymentDat e = MSHFlexGrid2.Te xtMatrix(MSHFle xGrid2.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, FirstPaymentDat e) Then
        BillType="Inter val 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.Ad dItem (MSHFlexGrid2.T extMatrix(MSHFl exGrid2.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








        "Jan Hyde" <StellaDrinker@ REMOVE.ME.uboot .comwrote in message
        news:bm5sa2tia3 s1slfspk8jfi5st 3thu5e68d@4ax.c om...
        Steven Smith <sluke4@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 FirstPaymentDat e As Date
        Dim CurrRowValue As Single
        Dim NumStudentsInFl ex2 As Single
        >
        NumStudentsInFl ex2 = MSHFlexGrid2.Ro ws
        CurrRowVal = 1
        Do While CurrRowVal < NumStudentsInFl ex2 'While counter
        is less than number of rows in all students grid
        >
        YesDate = 0
        MSHFlexGrid2.Ro w = CurrRowVal
        If MSHFlexGrid2.Te xtMatrix(CurrRo wVal, 2) = Date Then
        MSHFlexGrid1.Ad dItem
        (MSHFlexGrid2.T extMatrix(MSHFl exGrid2.Row, 0)) & vbTab &
        "First Bill"
        CurrRowVal = CurrRowVal + 1
        ElseIf MSHFlexGrid2.Te xtMatrix(CurrRo wVal, 3) = Date
        Then
        MSHFlexGrid1.Ad dItem
        (MSHFlexGrid2.T extMatrix(MSHFl exGrid2.Row, 0)) & vbTab &
        "Last Bill"
        CurrRowVal = CurrRowVal + 1
        Else
        FirstPaymentDat e =
        MSHFlexGrid2.Te xtMatrix(MSHFle xGrid2.Row, 2)
        YesDate = 0
        If Format(Date, "MM/DD/YYYY") =
        Format(DateAdd( "m", 1, FirstPaymentDat e), "MM/DD/YYYY") Then
        YesDate = 1
        If Format(Date, "MM/DD/YYYY") =
        Format(DateAdd( "m", 2, FirstPaymentDat e), "MM/DD/YYYY") Then
        YesDate = 1
        If Format(Date, "MM/DD/YYYY") =
        Format(DateAdd( "m", 3, FirstPaymentDat e), "MM/DD/YYYY") Then
        YesDate = 1
        If Format(Date, "MM/DD/YYYY") =
        Format(DateAdd( "m", 4, FirstPaymentDat e), "MM/DD/YYYY") Then
        YesDate = 1
        If Format(Date, "MM/DD/YYYY") =
        Format(DateAdd( "m", 5, FirstPaymentDat e), "MM/DD/YYYY") Then
        YesDate = 1
        If Format(Date, "MM/DD/YYYY") =
        Format(DateAdd( "m", 6, FirstPaymentDat e), "MM/DD/YYYY") Then
        YesDate = 1
        If Format(Date, "MM/DD/YYYY") =
        Format(DateAdd( "m", 7, FirstPaymentDat e), "MM/DD/YYYY") Then
        YesDate = 1
        If Format(Date, "MM/DD/YYYY") =
        Format(DateAdd( "m", 8, FirstPaymentDat e), "MM/DD/YYYY") Then
        YesDate = 1
        If Format(Date, "MM/DD/YYYY") =
        Format(DateAdd( "m", 9, FirstPaymentDat e), "MM/DD/YYYY") Then
        YesDate = 1
        If YesDate = 1 Then MSHFlexGrid1.Ad dItem
        (MSHFlexGrid2.T extMatrix(MSHFl exGrid2.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)
        >

        Comment

        Working...