Infinite Loop


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Infinite Loop

  1. #1
    Greg Guest

    Infinite Loop


    Hey guys,
    I made this loop as an error check in my user form. The purpose of the
    loop is so at least one non-negative number must be entered in before the
    optimal solution can be found with solver. But I'm having a problem. I
    want this to work so that once the "OK" button is clicked on the message
    box that displays,the message box simply disappears and the user has another
    shot at re-entering the data into the user form. I want the user form to
    stay where it is and not unload it. Of course, if the user still enters
    invalid data, the loop should still work. But, I've had trouble b/c sometimes
    this loop just goes on infinitely. Does anyone know how to do this?

    Dim X as Boolean
    Do While X = False

    If DCA > 0 Then
    X = True
    ElseIf DCB > 0 Then
    X = True
    ElseIf DCC > 0 Then
    X = True
    ElseIf DCD > 0 Then
    X = True
    ElseIf DCE > 0 Then
    X = True
    Else
    X = False
    MsgBox "You Must Enter at Least 1 Non-Negative Value for the Distribution
    Centers and Plants"
    End If

    Loop


  2. #2
    Peter Higgins Guest

    Re: Infinite Loop


    In this code the loop passes control to the msgbox, but not to the interface
    controlling your variables.

    If this is module code, redisplay your form modally.

    if this is form code, you don't need the loop, use a command button event
    or terminate, unload, queryunload event.

    "Greg" <valli59@aol.com> wrote:
    >
    >Hey guys,
    > I made this loop as an error check in my user form. The purpose of

    the
    >loop is so at least one non-negative number must be entered in before the
    >optimal solution can be found with solver. But I'm having a problem. I
    >want this to work so that once the "OK" button is clicked on the message
    >box that displays,the message box simply disappears and the user has another
    >shot at re-entering the data into the user form. I want the user form to
    >stay where it is and not unload it. Of course, if the user still enters
    >invalid data, the loop should still work. But, I've had trouble b/c sometimes
    >this loop just goes on infinitely. Does anyone know how to do this?
    >
    >Dim X as Boolean
    >Do While X = False
    >
    >If DCA > 0 Then
    > X = True
    >ElseIf DCB > 0 Then
    > X = True
    >ElseIf DCC > 0 Then
    > X = True
    >ElseIf DCD > 0 Then
    > X = True
    >ElseIf DCE > 0 Then
    > X = True
    >Else
    > X = False
    > MsgBox "You Must Enter at Least 1 Non-Negative Value for the Distribution
    >Centers and Plants"
    >End If
    >
    >Loop
    >



  3. #3
    Arthur Wood Guest

    Re: Infinite Loop


    Greg,

    This is not a good use of an infinite loop (There are very few GOOD uses
    for infinite loops). The problem that you have is this:

    What will happen in this loop if DCA is Positive? The value X is set
    to TRUE, and the Loop continues forever.(similarly if DCA ,=0 and DCB > 0,
    or DCA <= 0, DCB <= 0, and DCC > 0, and so on).

    You need to rethink the way to test the condition that you need, rather than
    using an infinite loop.

    Arthur Wood

    "Greg" <valli59@aol.com> wrote:
    >
    >Hey guys,
    > I made this loop as an error check in my user form. The purpose of

    the
    >loop is so at least one non-negative number must be entered in before the
    >optimal solution can be found with solver. But I'm having a problem. I
    >want this to work so that once the "OK" button is clicked on the message
    >box that displays,the message box simply disappears and the user has another
    >shot at re-entering the data into the user form. I want the user form to
    >stay where it is and not unload it. Of course, if the user still enters
    >invalid data, the loop should still work. But, I've had trouble b/c sometimes
    >this loop just goes on infinitely. Does anyone know how to do this?
    >
    >Dim X as Boolean
    >Do While X = False
    >
    >If DCA > 0 Then
    > X = True
    >ElseIf DCB > 0 Then
    > X = True
    >ElseIf DCC > 0 Then
    > X = True
    >ElseIf DCD > 0 Then
    > X = True
    >ElseIf DCE > 0 Then
    > X = True
    >Else
    > X = False
    > MsgBox "You Must Enter at Least 1 Non-Negative Value for the Distribution
    >Centers and Plants"
    >End If
    >
    >Loop
    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center