Link to home
Start Free TrialLog in
Avatar of Richard_XP
Richard_XPFlag for United States of America

asked on

how could I refer VB constant (enum) in C#

I have a VB function Public Sub ShowMessage(ByVal message As String, Optional ByVal messageStyle As MsgBoxStyle = MsgBoxStyle.DefaultButton1) and I need to call it from C#. How could I submit the second parameter.  In VB, I can use MsgBoxStyle.Critical, but in C#, it would give me the error "the name MsgBoxStyle doesn't exist in context". Should I import a library? thanks.
Avatar of rgn2121
rgn2121
Flag of United States of America image

That is part of Microsoft.VisualBasic, so check and see if it is referenced....
Avatar of Carl Tawn
You'll have to include the Microsoft.VisualBasic assembly into your project.

MsgBoxStyle is a VB only enum, you would have made life simpler for yourself if you had stuck to the more general .Net MessageBoxIcon type for your parameter.
Avatar of Richard_XP

ASKER

I can not find MsgBoxStyle in Microsoft.VisualBasic, the only thing available is VBCodeProvider. thanks.
SOLUTION
Avatar of rgn2121
rgn2121
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I can see it in the object Browser, but adding the assembly to Microsoft.VisualBasic does not allow you to get to MsgBox or the MsgBoxStyle Enums.  My guess is because this is really only a VB thing and not a .Net thing.  So using the MessageBox Class will allow for compatibility between VB and C#.
you are right, I need to add reference to microsoft.visualbasic first, then I can refer it. I will use messagebox instead
I stand corrected...Microsoft.VisualBasic.MsgBoxStyle is there... I still don't see MsgBox