Help me convert this to VB.Net

G

George Durzi

switch((Status) Enum.Parse(typeof(cUIHelper.Status),
dsJob.Tables[0].Rows[0]["STATUS"].ToString()))
{
case Status.Closed:
break;
}

works fine in C#

tried this in vb.net

Select Case CType([Enum].GetName(GetType(Status),
dsJob.Tables[0].Rows[0]["STATUS"].ToString()), Status)
Case Status.Closed
' blah blah
End Select

got this error:
 
G

George Durzi

Sorry, I hit Send too soon.

This is the error:
The value passed in must be an enum base or an underlying type for an enum,
such as an Int32. Parameter name: value

and my enum is defined as such

Enum Status

Open

Closed

End Enum
 
P

Phill. W

George Durzi said:
switch((Status) Enum.Parse(typeof(cUIHelper.Status), .. . .
Select Case CType([Enum].GetName(GetType(Status),
.. . .
Is there any particular reason you're calling a completely /different/
function in the VB Code? (as in GetName(), rather than Parse())?

This should work ...

Select Case DirectCast( Enum.Parse( GetType( Status ),
dsJob.Tables(0).Rows(0).Item("STATUS").ToString()) , Status )
Case Status.Closed
. . .
End Select

Or, even simpler still since VB allows you to "select" directly on
String values ...

Select Case dsJob.Tables(0).Rows(0).Item("STATUS").ToString()
Case Status.Closed.ToString()
. . .
End Select

HTH,
Phill W.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,190
Latest member
ClayE7480

Latest Threads

Top