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

## Recommended Posts

DrjonesDW3d    100
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 on other sites
DrjonesDW3d    100
Ok, nm figured it out. Turns out there is a NO_DATA_AVAILABLE and a NO_MORE_DATA_AVAILABLE

So to make this thread not completly worthless, whats with the [] part?

##### 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 = 5Dim [If] As StringFor [For] As Integer = 0 To [Dim]  If [If].Length = 0 Then ...Next