I have created my own Message Box ('
myMB
') and have used it 1000's of times successfully. It worked fine during debugging this AM.
However now, when my message box returns the
integer 1
(for example, I pressed the "Yes" button in the myMB Window) and the returned value is compared to 1, the debugger does not move to the code that it should... This sounds crazy and so my explanation may not seem to make plausible sense; so here is some example code.
If myMB.DialogResult = 1 Then
Stop
End If
The above example is exact (test) code I've used. When run step by step (or Run w/o stepping), the program DOES NOT 'Stop.' I have confirmed that
myMB.DialogResult = 1
and that
myMB.DialogResult = 1 evaluates to 'True'
but the code does not move to the 'Stop' statement.
Again, similar code worked an hour ago.
What is going on?!?!
IMPROVED QUESTION
As I mentioned I'd used my own message box 1000's of time (years) w/o a problem. Back when I wrote it, I was a relatively new programmer. I'm still not an expert, obviously, or I would have understood '
DialogResult
' as I do now. Thanks to Ralf's patient explanation that it was an '
Enum
' caused me to re-study its use. If I understood it back then as I do now, I would have written
myMB
much differently.
All that said, and while I am past my programming issue, my question as to why I'm seeing what I'm seeing remains.
Originally, and still now, using 'Shadows' with
DialogResult
I was/am able to assign
integer
values to
DialogResult
without Errors or Exceptions occuring in development or at Runtime. But at runtime in the class using
myMB
I cannot use
DialogResult
as expected.
So I wrote a Test Class to demonstrate this dilemna. In doing so, I taught myself what is, apparently, the correct way to use
DialogResult
. Commented out in the listing are various optional 'correct' values for
DialogResult
(as the
Enum
it was designed to be). The commented code represents my learning curve towards proper use of
DialogResult
.
Note: The Test Class is a form with a single button in it.
But using '
Shadows DialogResult as Integer = 0
' in the Test Class (and in my original code) compiles/runs and ~should~ therefore work, yes? But it does not work as expected. Note: Using '
Shadows
' and unCommenting those LOC ~does~ cause each of the Commented LOC to show and error....
Here below is the code for the Test Class. Below it, is code which uses that class and demonstrates the dilema.
My Public variable '
Response
' (e.g.,
myMB.Response
) gives me back an
integer
value set to the value of the button pushed in
myMB
. This works as expected. However, when
DialogResult
is 'Shadowed' to become an
integer
(w/o error),
DialogResult
is allowed to exist as ~~both~~ an
Enum
Value and as an
integer
in the using class. Despite this, when the code is stepped through in debug mode it does not stop at any of the offered
If/ElseIf
's where it seems as though it should stop, but only stops when it gets to the final
ElseIf
.
Can anyone explain what is happening... and not happening?
**Test Class Code**
Option Strict On
Option Explicit On
Imports System.Windows.Forms
Public Class frmMyMBDilema
Public Response As Integer = 999
Shadows DialogResult As Integer = 0
Private Sub frmMyMBDilema_Load(sender As Object, e As EventArgs) Handles Me.Load
End Sub
Private Sub btnDialogResultDilema_Click(sender As Object, e As EventArgs) Handles btnDialogResultDilema.Click
Response = 1
DialogResult = 1
Me.Close()
End Sub
Public Sub ShowIt()
Me.ShowDialog()
End Sub
End Class
**Code That Uses the Above Class**
Dim myMBTest As New frmMyMBDilema
myMBTest.ShowIt()
If myMBTest.DialogResult = DialogResult.OK Then
Stop
ElseIf CType(myMBTest.DialogResult, Integer) = 1 Then
Stop
ElseIf myMBTest.DialogResult = DialogResult.Yes Then
Stop
ElseIf myMBTest.DialogResult = DialogResult.OK Then
Stop
ElseIf myMBTest.Response = 1 Then
Stop
End If
What I have tried:
1) Written test code elsewhere in the same Sub
2) Deleted and rewrote the initial offending code
3) Wrote simple test code
4) Closed this program within Visual Studio and reloaded it
5) ReCompiled the DLL within which my Message Box exists
6) Closed Visual Studio and reloaded it and the program
7) Shut down my computer. The reloaded it, VS and the program
8) Googled for answers and (not surprisingly) no directly related search results were found