Sign in to follow this  
DrjonesDW3d

[.net] Comparison of enumerated types in VB.NET

Recommended Posts

Ok, first off I don't know VB, so maybe I'm missing something obvious. However, sometimes I have to program something in it as is the case now. The problem I am having is that I have a .NET object that inherets from Exception with a field defined that is an enumerated type (representing the type of error). That object and code was written in C#, but I don't think that matters. So anyways, I catch the exception and want to check for that kind of error. Basically I have a loop iterating over a function call. If the function call has an error, I want a popup, unless the error is that there is no more data, which means just to stop. The code looks something like this.
       Try
            While True
                f(param1)
            End While
       Catch ex As MyExcep
            If ex.error <> MyObj.ERROR.NO_DATA_AVAILABLE Then
                ErrorMessage(ex)
            End If
       End Try
Where ErrorMessage just pops up a dialog box with info about the error. The problem is that I am getting the No data availible exception (as is expected) but the dialog box pops up. Why doesn't this work? If I do
       Catch ex As MyExcep
            If ex.error <> 50 Then
                ErrorMessage(ex)
            End If
       End Try
where 50 is the int that the enumerated type maps to, it works the way I want. However, the whole point of using enumerated types is to be able to use the actual error instead of just a random magic number. Anyone know why it works this way? Also, kind of wierd was that using auto complete it filled in the line as MyObj.[ERROR].NO_DATA_AVAILABLE with the []. Anyone know why?

Share this post


Link to post
Share on other sites
"Error" is a reserved word in Visual Basic.

To use a reserved word as a variable, you have to enclose it in []'s.

So you could do something completely stupid like this:

Dim [Dim] As Integer = 5
Dim [If] As String

For [For] As Integer = 0 To [Dim]
If [If].Length = 0 Then ...
Next

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this