• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 447
  • Last Modified:

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.
0
Richard_XP
Asked:
Richard_XP
  • 4
  • 2
  • 2
2 Solutions
 
rgn2121Commented:
That is part of Microsoft.VisualBasic, so check and see if it is referenced....
0
 
Carl TawnSystems and Integration DeveloperCommented:
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.
0
 
Richard_XPAuthor Commented:
I can not find MsgBoxStyle in Microsoft.VisualBasic, the only thing available is VBCodeProvider. thanks.
0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
rgn2121Commented:
Actually...that might not exist at all...You will have to use MessageBox.Show(), which is the .Net version
0
 
Carl TawnSystems and Integration DeveloperCommented:
It is in there. Have you actually added a reference the the Microsoft.VisualBasic assembly, or have you only imported the namespace?
0
 
rgn2121Commented:
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#.
0
 
Richard_XPAuthor Commented:
you are right, I need to add reference to microsoft.visualbasic first, then I can refer it. I will use messagebox instead
0
 
rgn2121Commented:
I stand corrected...Microsoft.VisualBasic.MsgBoxStyle is there... I still don't see MsgBox
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now