Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27349

[RESOLVED] What's wrong with my MessageBox ?

$
0
0
Hi, I'm trying to get a return result from a MessageBox like this:

vb.net Code:
  1. Private Sub Button9_Click(sender As System.Object, e As System.EventArgs) Handles Button9.Click
  2.         Dim ask As String = "Are you sure you want to delete this record ?"
  3.         Dim flag As Boolean = True
  4.  
  5.         MessageBox.Show(ask, "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)
  6.         flag = CBool(Windows.Forms.DialogResult.No)
  7.  
  8.         If flag Then Exit Sub
  9.  
  10.     End Sub
Clicking either the 'Yes' or 'No' button on the MessageBox always returns flag = True.
I've tried 'Dim flag As Boolean = False' and ran the code but still get 'True', so it's not just bypassing the code, it's actually setting flag to True.

The MsgBox title is 'Delete' as it ought to be, the correct question is being asked and the 'Warning' icon is being displayed.
I originally had ' flag = Windows.Forms.DialogResult.No' (i.e. without the CBool( ... ) but Option Strict insisted !.
Oh... and I've also tried 'flag = CBool(Windows.Forms.DialogResult.Yes)'... still with the same always 'True' result.

Poppa.

Viewing all articles
Browse latest Browse all 27349

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>