By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,805 Members | 1,273 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,805 IT Pros & Developers. It's quick & easy.

While loop

Ali Rizwan
100+
P: 927
Hi
I want to make a loop which will be terminated when data record ends or statement will be true.
Sep 8 '07 #1
Share this Question
Share on Google+
6 Replies


Expert 5K+
P: 8,434
I want to make a loop which will be terminated when data record ends or statement will be true.
What do you mean exactly by "when data record ends"? Are you looping through the fields in the record, or what? As far as "statement will be true", in VB a statement isn't True or False. You must be referring to some sort of expression or condition that you want to be True. To drop out of a While loop when a condition is true, you just code that condition in the While statement.
Sep 9 '07 #2

Ali Rizwan
100+
P: 927
What do you mean exactly by "when data record ends"? Are you looping through the fields in the record, or what? As far as "statement will be true", in VB a statement isn't True or False. You must be referring to some sort of expression or condition that you want to be True. To drop out of a While loop when a condition is true, you just code that condition in the While statement.
I want to add items from a database in combobox using loop.
I dont know which loop is used is it do while?
Plz tell how can i do
Sep 9 '07 #3

QVeen72
Expert 100+
P: 1,445
Hi Ali,

Use DO Loop:

Expand|Select|Wrap|Line Numbers
  1. Combo1.Clear
  2. RST.MoveFirst
  3. Do While Not RST.EOF
  4.   Combo1.AddItem RST(0) 
  5.   RST.MoveNext
  6. Loop
  7.  
Regards
Veena
Sep 9 '07 #4

Expert 5K+
P: 8,434
Use DO Loop ...
Good advice. But personally, I feel the Until seems more sensible in such a situation (though of course, the end result is the same). For example...

Expand|Select|Wrap|Line Numbers
  1. Combo1.Clear
  2. With Rst
  3.   .MoveFirst
  4.   Do While Until .EOF
  5.     Combo1.AddItem .Fields(0) 
  6.     .MoveNext
  7.   Loop
  8. End With
Sep 9 '07 #5

pureenhanoi
100+
P: 175
Good advice. But personally, I feel the Until seems more sensible in such a situation (though of course, the end result is the same). For example...

Expand|Select|Wrap|Line Numbers
  1. Combo1.Clear
  2. With Rst
  3.   .MoveFirst
  4.   Do While Until .EOF
  5.     Combo1.AddItem .Fields(0) 
  6.     .MoveNext
  7.   Loop
  8. End With
i havenot try your code yet. But the standard Loops in VB maybe haven't Do While Until.
some standard loops are:
Do While (condition)
.........
Loop

Do Until (condition)
..........
Loop

While (condition)
..............
Wend

Ofcourse, its great if we have many out of standard loops.
Sep 10 '07 #6

Expert 5K+
P: 8,434
Sorry, Do While Until was an error. I failed to remove the While.
Sep 10 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.