Graceful exit from SolverSolve Solver loop found 
Author Message
 Graceful exit from SolverSolve Solver loop found

Using Excel XP and Win XP

Just started using SolverSolve in a loop to solve a series of problems
(140 problems or 18 hrs).  Got it working OK and have just found a way
to gracefully abort the loop at the end of the current problem.  Could
not find this noted anywhere else and thought I might post it.  Still
have one problem that I could use help with that I will put in a
different thread.

Before I get to the sample, has anyone else made VBA edits in Excel
XP, closed the spreadsheet using the X in the upper right, and had the
sheet close without getting the "Do you want to save changes..."
screen to pop up?  I have but I can't seem to recreate it on demand
yet.  But it has made me mad at Excel XP a couple of times already (3
wks).  Some other bugs in there too, ain't there?

OK, I want to be able to close a loop containing a SolverSolve problem
gracefully at the end of the current loop (before the next problem
loads).  I had trouble with this because solver seems to swallow the
mouse during its operation.  But keys go through ok.  Note that this
will probably effect the Max. Iterations and/or the Max. Time popups.
But that is part of my problem in the other thread.

Hope this helps someone,
Brian

Make a form with two buttons.  I named these cmdStart and cmdStop.
You could get by with only one, but I wanted to be sure that Excel was
done opening the form, so the cmdStart button is really just a delay
to let Excel finish watever it has to do.

The code in the form looks like this:

---------------

Option Explicit

Private Sub UserForm_Activate()

    cmdStart.Visible = True
    cmdStop.Visible = False

End Sub

Private Sub cmdStart_Click()

    cmdStart.Visible = False
    cmdStop.Visible = True
    cmdStop.SetFocus
    Call doIt

End Sub

Private Sub cmdStop_Click()

    MsgBox "The Clicks are swallowed by Solver :>( !"
    End

End Sub

Private Sub cmdStop_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)

    MsgBox "But the KeyPress(es) aren't :>) !"
    End

End Sub

Sub doIt()

    Do

        ' check if there are any more problems to do

        DoEvents

        ' load the new problem

        SolverSolve UserFinish:=True

        ' unload the solved problem

    Loop

End Sub



Tue, 28 Sep 2004 18:30:17 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Graceful Exit

2. Graceful exit?

3. Loop Exit after Last Find

4. Looping Solver

5. running Solver in a loop

6. Selection.Find.Execute does not find the text 2nd time thru the loop

7. Exiting while loops

8. Exit Loop on keypress?

9. how to exit loop?

10. How to exit if statement and not continue with Do Loop


 
Powered by phpBB® Forum Software © phpBB Group