-
February 24th, 2014, 09:21 AM
#1
Do while loop
Can anyone please help me with a Do while Not loop.
I'm very new to programming:
I need to check and print a list, and limit it to 5 names.
Do While Not rsP.EOF And iCount > 5
sLT = sLT & rsP![Name] & vbNewLine
iCount = iCount + 1
rsP.MoveNext
Loop
If rsP.RecordCount > 5 Then
sLT = sLT & "..."
End If
right now it will not print the list, if I take out iCount > 5, it prints, but I need to limit it to only 5 names maximum to print?
Thanks
-
February 24th, 2014, 09:50 AM
#2
Re: Do while loop
The issue is with iCount > 5 , I just need to understand how can I get it to show if the sLT is less than 5 and if its over 5 than limits to show 5 names as maximum
-
February 24th, 2014, 07:47 PM
#3
Re: Do while loop
Separate it:
Code:
Do While Not rsP.EOF
sLT = sLT & rsP![Name] & vbNewLine
iCount = iCount + 1
rsP.MoveNext
If rsP.RecordCount Mod 5 Then ' every 5th time only
sLT = sLT & "..."
End If
Loop
-
February 26th, 2014, 04:04 AM
#4
Re: Do while loop
Originally Posted by salman afzal
The issue is with iCount > 5 , I just need to understand how can I get it to show if the sLT is less than 5 and if its over 5 than limits to show 5 names as maximum
read your statement out loud...
DO while NOT EOF and icount GREATER than 5..... erm... two choises here... not EOF as first and greater than 5 as second...
you want : DO while NOT EOF and NOT icount GREATER than 5
all your really missing is the brackets...
Code:
Do While Not (rsP.EOF And iCount > 5)
Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
WPF Articles : 3D Animation 1 , 2 , 3
Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.
-
February 26th, 2014, 12:29 PM
#5
Re: Do while loop
Kind of confusing, still. I like my way.
Plus, he wanted to print 5 per line, then a break, right?
-
February 27th, 2014, 02:06 AM
#6
Re: Do while loop
Another option would be to test only the eof condition in the do while portion and then use an exit do when icount reaches 5
Always use [code][/code] tags when posting code.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|