2014-09-25 60 views
0

好日子所有,我是有一些麻煩我MSGBOX與vbyesnocancelMSGBOX和vbyesnocancel

提示•此代碼一切工作就好了「但」我需要點擊多次是,否,取消激活其功能

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 

•使用此代碼「否」和「取消」功能不工作

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 
+3

你真的應該使用MessageBox.Show(),而不是傳統的msgbox()函數。我已經看到MsgBox的微妙的錯誤,其中對話框不會正確地出現在應用程序的前面。 – 2014-09-25 03:14:45

回答

1

試試這個,你所要求的輸入與現有代碼的3倍。

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 

,或者你可以使用一個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 
1

嘗試是這樣的:

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 
+0

也感謝先生這一個也很完美 – NewbieVB 2014-09-25 03:26:56

+0

或者至少投票答案? – eniacAvenger 2014-09-25 03:36:46

+0

投了它先生再次感謝.. – NewbieVB 2014-09-25 03:40:38