DoEvents not working

  • Thread starter Thread starter P. Prosper
  • Start date Start date
P

P. Prosper

Hello,
Could someone give me a hint why my CancelPrint Logic won't work despite the
DoEvents ?

in form lvele declaration I have
Public Shared CancelPrint As Boolean

'Printing Logic
Do While rsAccount.EOF = False And CancelPrint = False
Application.DoEvents()
SelFormula = "{Socios.NumSocio} in " & Chr(34) &
rsAccount.Fields("NumSocio").Value & Chr(34) & " to " & Chr(34) &
rsAccount.Fields("NumSocio").Value & Chr(34)
Dim crptStatement As New crptStatements_ATH
If ChkNotificacion.CheckState = CheckState.Unchecked Then
crptStatement.Section7.SectionFormat.EnableSuppress = True
Else
crptStatement.Section7.SectionFormat.EnableSuppress = False
End If
crptStatement.RecordSelectionFormula = SelFormula
i = i + 1
ProgressBar1.Value = i
crptStatement.PrintToPrinter(1, False, 0, 0)
rsAccount.MoveNext()
Loop

If CancelPrint Then
MsgBox("Printing Canceled By User", MsgBoxStyle.Exclamation)
End If

Private Sub CmdCancel_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles
'This togles the CancelPrint flag
CmdCancel.Click
CancelPrint = True
End Sub
 
Hi P,

If I am right, do than not hit to hard against your head.

I think that If is never tested, just placing the loop a little bit lower
will maybe help.

Cor

i = i + 1
ProgressBar1.Value = i
crptStatement.PrintToPrinter(1, False, 0, 0)
rsAccount.MoveNext()
If CancelPrint Then
MsgBox("Printing Canceled By User", MsgBoxStyle.Exclamation)
End If
Loop
 
* "P. Prosper said:
Could someone give me a hint why my CancelPrint Logic won't work despite the
DoEvents ?

in form lvele declaration I have
Public Shared CancelPrint As Boolean

Why is 'CancelPrint' shared?
 
to be honest ....
CancelPrint is shared out of despair :-). Nevertheless this should work
anyway (or not ?).

about Cor's suggestion ...
If CancelPrint Then
MsgBox("Printing Canceled By User", MsgBoxStyle.Exclamation)
End If
is just a mean to notify the user that printing was canceled ..

the problem is that the event ...
Private Sub CmdCancel_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles CmdCancel.Click

CancelPrint = True

End Sub

is not being trigered in spite of the DoEvents()
 
Hi P,

What is that cmdcancel is that a button or something?

(And maybe more are you sure that that process is running and not all is
sended to a buffer?)

I would set a counter on a form (assuming that there is a form, so you can
see where it is)

Cor
 
in fact if I just rem out crptStatement.PrintToPrinter(1, False, 0, 0)
the code works ..."sometimes" provided I click the cancel Button fast enough
<g>

P. Prosper said:
to be honest ....
CancelPrint is shared out of despair :-). Nevertheless this should work
anyway (or not ?).

about Cor's suggestion ...
If CancelPrint Then
MsgBox("Printing Canceled By User", MsgBoxStyle.Exclamation)
End If
is just a mean to notify the user that printing was canceled ..

the problem is that the event ...
Private Sub CmdCancel_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles CmdCancel.Click

CancelPrint = True

End Sub

is not being trigered in spite of the DoEvents()



despite
 
* "P. Prosper said:
to be honest ....
CancelPrint is shared out of despair :-). Nevertheless this should work
anyway (or not ?).

I would expect your code to work.
 
* "P. Prosper said:
Could someone give me a hint why my CancelPrint Logic won't work despite the
DoEvents ?

Just for my information: What doesn't work? Doesn't it cancel or is no
messagebox shown?
 
It just won't cancel ... wich is of paramount importance giving that app
will be printing anywhere from 1,500 to 2,000 statements <g>.
I wonder if will have to use some complex threading scheme to get it to
work, I'd hate to do that ...
 
* "P. Prosper said:
It just won't cancel ... wich is of paramount importance giving that app
will be printing anywhere from 1,500 to 2,000 statements <g>.
I wonder if will have to use some complex threading scheme to get it to
work, I'd hate to do that ...

Did you try to output the cancel variable's value? Is it really set to
'True'?
 
* "P. Prosper said:
The problem is that the loop is blocking the CmdCancel click event from
happening

You may want to put the loop into a separate thread (keyword:
multithreading).
 
Hi Herfried,
You may want to put the loop into a separate thread (keyword:
multithreading).

For looping through less than 10000 records in a recordset and trying to
stop that with a button?

Than it will be even more impossible in my opinion.

Cor
 
* "Cor Ligthert said:
For looping through less than 10000 records in a recordset and trying to
stop that with a button?

Than it will be even more impossible in my opinion.

What? The OP's code is blocking events from being processed, and
'Application.DoEvents' doesn't seem to help in his case.
 
P. Prosper said:
The problem is that the loop is blocking the CmdCancel click event
from happening

Is the button enabled? Does the button change the visual state when holding
down the mouse? Have you already tried setting a breakpoint in the click
event handler? Do you use Debug or Release configuration? Is the
"Handles" clause still there? Is it's name really cmdCancel? Is there any
interaction reaction while printing?


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
What? The OP's code is blocking events from being processed, and
'Application.DoEvents' doesn't seem to help in his case.
Only when he is not fast enough with clicking he said read the complete
thread please.

Cor
 
* "Cor Ligthert said:
Only when he is not fast enough with clicking he said read the complete
thread please.

Be sure that I read the thread. The problem will go away when using
multithreading.
 
Back
Top