While loop

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ali Rizwan
    Banned
    Contributor
    • Aug 2007
    • 931

    #1

    While loop

    Hi
    I want to make a loop which will be terminated when data record ends or statement will be true.
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Originally posted by Ali Rizwan
    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.

    Comment

    • Ali Rizwan
      Banned
      Contributor
      • Aug 2007
      • 931

      #3
      Originally posted by Killer42
      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

      Comment

      • QVeen72
        Recognized Expert Top Contributor
        • Oct 2006
        • 1445

        #4
        Hi Ali,

        Use DO Loop:

        [code=vb]
        Combo1.Clear
        RST.MoveFirst
        Do While Not RST.EOF
        Combo1.AddItem RST(0)
        RST.MoveNext
        Loop
        [/code]

        Regards
        Veena

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          Originally posted by QVeen72
          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...

          [code=vb]Combo1.Clear
          With Rst
          .MoveFirst
          Do While Until .EOF
          Combo1.AddItem .Fields(0)
          .MoveNext
          Loop
          End With[/code]

          Comment

          • pureenhanoi
            New Member
            • Mar 2007
            • 175

            #6
            Originally posted by Killer42
            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...

            [code=vb]Combo1.Clear
            With Rst
            .MoveFirst
            Do While Until .EOF
            Combo1.AddItem .Fields(0)
            .MoveNext
            Loop
            End With[/code]
            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.

            Comment

            • Killer42
              Recognized Expert Expert
              • Oct 2006
              • 8429

              #7
              Sorry, Do While Until was an error. I failed to remove the While.

              Comment

              Working...