Reputation: 29
Good day to all, i was having some trouble with my msgbox prompting with vbyesnocancel
• This code everything is working just fine "BUT" i needed to click multiple yes, no, cancel to activate its function
Private Sub cbEnableDeductions_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbEnableDeductions.Click
If MsgBox("Do You want To Enable deductions?", vbYesNoCancel) = MsgBoxResult.Yes Then
cbEnableDeductions.Checked = True
txtSSS.Enabled = True
txtHDMF.Enabled = True
txtPhilHealth.Enabled = True
ElseIf MsgBox("Do You want To Enable deductions?", vbYesNoCancel) = MsgBoxResult.No Then
cbEnableDeductions.Checked = True
Total()
ElseIf MsgBox("Do You want To Enable deductions?", vbYesNoCancel) = MsgBoxResult.Cancel Then
cbEnableDeductions.CheckState = False
End If
End Sub
• with this code "NO" and "CANCEL" functions are not working
Private Sub cbEnableDeductions_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbEnableDeductions.Click
If MsgBox("Do You want To Enable deductions?", vbYesNoCancel) = MsgBoxResult.Yes Then
cbEnableDeductions.Checked = True
txtSSS.Enabled = True
txtHDMF.Enabled = True
txtPhilHealth.Enabled = True
ElseIf vbYesNoCancel = MsgBoxResult.No Then
cbEnableDeductions.Checked = True
Total()
ElseIf vbYesNoCancel = MsgBoxResult.Cancel Then
cbEnableDeductions.CheckState = False
End If
End Sub
Upvotes: 0
Views: 1932
Reputation: 593
try this, you are asking the input for 3 times with your existing code.
Dim result As MsgBoxResult = MsgBox("Do You want To Enable deductions?", vbYesNoCancel)
If result = MsgBoxResult.Yes Then
cbEnableDeductions.Checked = True
txtSSS.Enabled = True
txtHDMF.Enabled = True
txtPhilHealth.Enabled = True
ElseIf result = MsgBoxResult.No Then
cbEnableDeductions.Checked = True
Total()
ElseIf result = MsgBoxResult.Cancel Then
cbEnableDeductions.CheckState = False
End If
or you can use a CASE
Select Case MsgBox("Do You want To Enable deductions?", vbYesNoCancel)
Case MsgBoxResult.Yes
cbEnableDeductions.Checked = True
txtSSS.Enabled = True
txtHDMF.Enabled = True
txtPhilHealth.Enabled = True
Case MsgBoxResult.No
cbEnableDeductions.Checked = True
Total()
Case MsgBoxResult.Cancel
cbEnableDeductions.CheckState = False
End Select
Upvotes: 1
Reputation: 875
Try something like this:
Private Sub cbEnableDeductions_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbEnableDeductions.Click
Dim msgBoxResult = MsgBox("Do You want To Enable deductions?", vbYesNoCancel)
If msgBoxResult = MsgBoxResult.Yes Then
cbEnableDeductions.Checked = True
txtSSS.Enabled = True
txtHDMF.Enabled = True
xtPhilHealth.Enabled = True
ElseIf msgBoxResult = MsgBoxResult.No Then
cbEnableDeductions.Checked = True
Total()
ElseIf msgBoxResult = MsgBoxResult.Cancel Then
cbEnableDeductions.CheckState = False
End If
End Sub
Upvotes: 1