Resolved MessageBox 'No' code not executed after printing.

Post number 2 has been selected as best answer.

benshaws

Hobbyist Programmer
Joined
Sep 19, 2013
Messages
8
Location
Leeds, UK
Programming Experience
5-10
I have a problem with a MessageBox YesNo when sending output to the printer. The MessageBox appears on screen and closes if Yes is selected by the user, which is as wanted.

However, if No is selected I want to reprint the document. To do this I show another MessageBox with RetryCancel and some code to loop printing. I don't understand why but none of the 'No' code is executed.

Is it something to do with output going to the printer?

Any help would be very much appreciated.:)

The application is for my wife's shop and I need to be able to do a reprint if the printer jams.

See code below.........................

VS 2019.
.Net Framework 4.7.2



VB.NET:
'Confirm if receipt printed correctly with the user.
Dim resultDlg As Integer
resultDlg = MessageBox.Show("Karen," & Chr(10) & Chr(10) & "Did your receipt print ok?", "Receipt Printing", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
'Reprint the receipt if not printed.

If resultDlg = DialogResult.No Then
Dim resultDlg2 As Integer
Do While resultDlg2 = DialogResult.Retry
resultDlg2 = MessageBox.Show("Karen," & Chr(10) & Chr(10) & "Reprint the receipt again?", "Reprint receipt", MessageBoxButtons.RetryCancel, MessageBoxIcon.Question)
ReceiptDocument.PrinterSettings.Copies = 1
ReceiptDocument.DefaultPageSettings.Landscape = True
ReceiptDocument.Print()
Loop
ElseIf resultDlg = DialogResult.Yes Then
'Reset the receipt datatable to empty after printing.
ReceiptDataTable.Clear()
'Set the next page number.
pagenumber = 1 + pagenumber
End If




I hope left hand align is OK. Or should I indent when posting on the forum.
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,412
Location
Norway
Programming Experience
10+
Dim resultDlg2 As Integer
Do While resultDlg2 = DialogResult.Retry
DialogResult is the type, so change the variable from type Integer to type DialogResult.

Since the initial value is not DialogResult.Retry the Do block is never entered. The initial value in your code is 0, which convert to DialogResult value None. DialogResult.None <> DialogResult.Retry.

Also, what happens inside that block when result is Cancel? Do you still print one more time? I suggest getting rid of that variable and use MessageBox expression directly:
VB.NET:
Do While MessageBox.Show("retry?", "", MessageBoxButtons.RetryCancel) = DialogResult.Retry
    'print
Loop
 

benshaws

Hobbyist Programmer
Joined
Sep 19, 2013
Messages
8
Location
Leeds, UK
Programming Experience
5-10
Thanks JohnH,

Wow. That was a quick reply.:D

I see now where I've gone wrong with your explanation.(y)

Will amend and come back.
 

benshaws

Hobbyist Programmer
Joined
Sep 19, 2013
Messages
8
Location
Leeds, UK
Programming Experience
5-10
Hi again JohnH,

I was not expecting such a quick reply, so I had started on another part of this program. Have now just implemented those changes and your suggestion as well and all is good.

Will mark as answered.

Thanks you for the responding so quickly and the advice given. :D (y)
 

benshaws

Hobbyist Programmer
Joined
Sep 19, 2013
Messages
8
Location
Leeds, UK
Programming Experience
5-10
PS. Just noticed this is in the wrong sub forum. Should have asked in the "Windows Forms". Not "Web Forms".

Sorry for that.
 
Top Bottom