473,408 Members | 2,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

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 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
Jul 7 '06 #1
3 1122
The "Loop" keyword can not be in a conditional statement, like an IF. If
you are using 2005, use the continue statement.
"Steven Smith" <sl****@webbox.comwrote in message
news:XL*******************@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

Jul 7 '06 #2
Steven Smith <sl****@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)

Jul 7 '06 #3
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


"Jan Hyde" <St***********@REMOVE.ME.uboot.comwrote in message
news:bm********************************@4ax.com...
Steven Smith <sl****@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)

Jul 7 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Jeannie | last post by:
Hello group! I'm in Europe, traveling with my laptop, and I don't any compilers other than Borland C++ 5.5. available. I also don't have any manuals or help files available. Sadly, more...
102
by: Skybuck Flying | last post by:
Sometime ago on the comp.lang.c, I saw a teacher's post asking why C compilers produce so many error messages as soon as a closing bracket is missing. The response was simply because the compiler...
5
by: Guoqi Zheng | last post by:
I think I have this kind of problem very often, now it is really making me crazy. VS.NET always want to change my html code. Ok, that is fine as long as Vs.Net can ask my confirmaton first. For...
15
by: sparks | last post by:
We get more and more data done in excel and then they want it imported into access. The data is just stupid....values of 1 to 5 we get a lot of 0's ok that alright but 1-jan ? we get colums...
2
by: clinttoris | last post by:
Hello, If someone could help me it would be appreciated as I am not having much luck. I'm struggling with my asp code and have some questions relating to asp and oracle database. First...
6
by: Luke - eat.lemons | last post by:
Hi, Im pretty new to asp so all light on this question would be great. Basically i need to test to see what value is set (where to retrieve the data from) so ive done it like this: If...
50
by: John Salerno | last post by:
I know it's popular and very handy, but I'm curious if there are purists out there who think that using something like: for x in range(10): #do something 10 times is unPythonic. The reason I...
0
by: raylopez99 | last post by:
I ran afoul of this Compiler error CS1612 recently, when trying to modify a Point, which I had made have a property. It's pointless to do this (initially it will compile, but you'll run into...
1
by: Robocop | last post by:
Having just started using C again after some years off, i've been stumped by a problem i think someone more experienced could probably solve pretty easily. I have these 4 objects (vectors), and i...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.