[Gambas-user] How to exit loop and close the form

Matti math.eber at ...221...
Sun Nov 21 18:20:27 CET 2010


You have to specify a delay to Wait. From the docs:
"If Delay is not specified, the function processes all pending events and
returns immediately. In that specific case, input events (keyboard and mouse)
are ignored."

Try it like this:

Public Sub Form_Open()
  shouldStop = False
  Me.Show
  doIt
End

Public Sub btnStop_Click()
  shouldStop = True
End

Public Sub doIt()
  Dim i As Integer, j As Integer

  For i = 1 To 100
    If shouldStop = True Then Break
    ProgressBar1.Value = i / 100

    For j = 1 To 100
      If shouldStop = True Then Break
      ProgressBar2.Value = j / 100
      Print i, j	' My job here
      Wait 0.1
    Next

    Wait 0.1
  Next

  Me.Close()
End



Am 21.11.2010 15:45, schrieb Phạm Quang Dương:
> Hi,
> 
> I want create a dialog form which showes the current progress and let user
> stop the operation and close this dialog by clicking a Cancel button
> On form1 I have 2 progress bars and 1 button:
> 
> Private shouldStop as Boolean
> 
> Private Sub Form_Open()
> shouldStop = False
> Me.Show()
> doIt() 'Main loop of the operation
> End
> 
> Private Sub Button1_Click()
> shouldStop = True
> Me.Close()
> End
> 
> Private Sub doIt()
> Dim i As Interger, j As Interger
> i = 1
> Repeat
> j = 1
> Repeat
> Wait 'Let user click Cancel button
> ' My job here
> ProgressBar2.Value = j / 100
> j += 1
> Until shouldStop Or j = 100
> ProgressBar1.Value = i / 100
> i += 1
> ProgressBar2.Reset()
> Until shouldStop Or i = 100
> Me.Close()
> End
> 
> On FMain I call:
> 
> form1.ShowDialog()
> 
> In real-time when I click Cancel button first time, the operation (progress
> bar) stoppes but the form does not close until I click Cancel button the
> second time.
> 
> I think that my code is bad but I can not find the better solution. Please
> help! Thank you.
> ------------------------------------------------------------------------------
> Beautiful is writing same markup. Internet Explorer 9 supports
> standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
> Spend less time writing and  rewriting code and more time creating great
> experiences on the web. Be a part of the beta today
> http://p.sf.net/sfu/msIE9-sfdev2dev
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
> 




More information about the User mailing list