Home > Blockchain >  How to Pause my code while user click button in another form in VB.NET
How to Pause my code while user click button in another form in VB.NET

Time:07-12

This is the code as you notice. I want stop the code if EndBill_Form Show. If user click save button the code will continue. I tried frm.ShowDialog() and worked fine but there is two buttons in another form Save and cancel. If I press cancel button also execute the code

If ItemsNoLbl.Text = "0" Then
            MsgBox("There is no item to sale")
            Exit Sub
        Else
            Dim frm As New EndBill_FRM
            frm.CustomerLbl.Text = "Customer Name : "   CustomerCmb.Text
            If CustomerCmb.Enabled = False Then
                frm.BalanceLbl.Text = "Balance: 0&"
                frm.LastDebtLbl.Text = "0"
                frm.BalLbl.Text = "0"
            Else
                frm.BalanceLbl.Text = "Balance:"   BalanceLbl2.Text
                frm.LastDebtLbl.Text = DebtLbl2.Text
                frm.BalLbl.Text = BalanceLbl.Text
            End If
            frm.totalLbl2.Text = TotalLbl2.Text
            frm.totalLbl.Text = TotalLbl.Text
            frm.debt = Val(DebtLbl2.Text)
            frm.totalBill = Val(TotalLbl2.Text)
            frm.balance = Val(BalanceLbl.Text)
            frm.Show()
            ' ****** Here should stop *****
            
            ' ****** Here should continue *****
            If CustomerCmb.Enabled = False Then
                InsertSalse()
            Else
                Dim debt As Decimal = Val(DebtLbl2.Text)
                Dim totalBill As Decimal = Val(TotalLbl2.Text)
                Dim total As Decimal = debt   totalBill
                If total < Val(BalanceLbl.Text) Then
                    InsertSalse()
                Else
                    MsgBox("The sale could not be completed because the invoice amount exceeded the available balance")
                    Exit Sub
                End If
            End If
            MsgBox("Saved Seccessfully!")
            UpdateQuantity()
            New Sale_Form.Show()
        End If

Please help me

CodePudding user response:

' ****** Here should stop *****
frm.ShowDialog()

'Tag the form (more options than DialogResult) and hide the form
Dim frmTag As String = frm.Tag
frm.Close()
If frmTag = "Stop" Then
   'Your logic decision goes here
End If
' ****** Here should continue *****
  • Related