Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How can I leave a while block in VB6?

Posted on 2005-05-08
7
Medium Priority
?
1,753 Views
Last Modified: 2006-11-18
I've a while ... Wend block in VB6 - besides the basic condition to run the while block (eg: While MyRecordSet.EOF = False), I make a IF block test inside the while and when the condition is meet I want to stop running the While block (in VB.NET is possible to do Exit while) - How can I do the same in VB6?

Thanks and regards.
Miguel
0
Comment
Question by:LMGONCA
7 Comments
 
LVL 97

Accepted Solution

by:
Lee W, MVP earned 1000 total points
ID: 13955908
If you use a do loop instead you can exit the loop with

Exit Do
0
 
LVL 97

Expert Comment

by:Lee W, MVP
ID: 13955910
0
 
LVL 18

Expert Comment

by:JR2003
ID: 13955969
"Exit While" doesn't work in VB6.
You could change your "While" loop to a "Do While" loop.

While not MyRecordSet.EOF
    ...
WEnd

Would be changed to:

Do While not MyRecordSet.EOF
    ...
    If condtion Then
        Exit Do
    End IF
Loop


Or you could just use an old fasioned GoTo statement:

While not MyRecordSet.EOF
    ...
    If condtion Then
        Goto MyLabel
    End IF
WEnd
MyLabel:

PS: Use of GoTo statements is not generally considered to be good programing practice.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 13956277
While...Wend is considered to be VERY old code, and was kept in VB 6 simply for compatability with previous versions of VB.  YOu really should use

Do While...Loop   or Do Until....Loop

as alternative coding structures.

AW
0
 
LVL 6

Expert Comment

by:cjard
ID: 13958225
While myInteger < 100

  ...

  if someTestShowsWeMustExitLoop Then
    myInteger = 101
    GoTo EndOfLoop
  endif

  ...
  ...
EndOfLoop:
WEnd

0
 
LVL 101

Expert Comment

by:mlmcc
ID: 13960310
In your case you can't change the main condition for the loop try it like this

dim boolContinue as boolean
boolContinue = True
While ((MyRecordSet.EOF = False) AND boolContinue)
    Your Code
     If (Condition to Exit)
        boolContinue = False
     Endif

Wend

Now it should exit when you run out of data or when you want it to.

mlmcc
0
 
LVL 9

Expert Comment

by:Naveen Swamy
ID: 13966079
hi,
use exit loop to exit on the basis of ur conditions

Regards,
M.Naveen Swamy
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month14 days, 22 hours left to enroll

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question