A
Adam Sandler
Hello,
I'm converting this code from VB:
Try
With serialPort
' snip
End With
Catch ex As Exception
MsgBox(ex.ToString)
End Try
And this is what I have:
try
{
// snip
}
catch (Exception ex)
{
MsgBox(ex.ToString);
}
I get an error which states, "The name 'MsgBox' does not exist in the
current context". I have "using System.Windows.Forms;" at the top of
the code.
So I did some looking around and found a couple of sites which say to
do this:
System.Windows.Forms.MessageBox.Show("Test");
But when I do either "MessageBox.Show("Test");" or "
MessageBox(ex.ToString);" I get this error
"System.Windows.Forms.MessageBox is a 'type' but is used like a
'variable'".
I'm really confused, I'm using the examples I see in other postings
and I have the required using statement... How can I get a msgbox to
appear on the screen? (I know this is a lousy example of handling an
exception... but the point of my post is asking about getting a msgbox
to work.)
Thanks!
I'm converting this code from VB:
Try
With serialPort
' snip
End With
Catch ex As Exception
MsgBox(ex.ToString)
End Try
And this is what I have:
try
{
// snip
}
catch (Exception ex)
{
MsgBox(ex.ToString);
}
I get an error which states, "The name 'MsgBox' does not exist in the
current context". I have "using System.Windows.Forms;" at the top of
the code.
So I did some looking around and found a couple of sites which say to
do this:
System.Windows.Forms.MessageBox.Show("Test");
But when I do either "MessageBox.Show("Test");" or "
MessageBox(ex.ToString);" I get this error
"System.Windows.Forms.MessageBox is a 'type' but is used like a
'variable'".
I'm really confused, I'm using the examples I see in other postings
and I have the required using statement... How can I get a msgbox to
appear on the screen? (I know this is a lousy example of handling an
exception... but the point of my post is asking about getting a msgbox
to work.)
Thanks!