Solved

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

Posted on 2011-03-08
8
415 Views
Last Modified: 2013-12-17
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
Comment
Question by:Richard_XP
  • 4
  • 2
  • 2
8 Comments
 
LVL 12

Expert Comment

by:rgn2121
ID: 35072230
That is part of Microsoft.VisualBasic, so check and see if it is referenced....
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 35072249
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
 
LVL 4

Author Comment

by:Richard_XP
ID: 35072275
I can not find MsgBoxStyle in Microsoft.VisualBasic, the only thing available is VBCodeProvider. thanks.
0
 
LVL 12

Assisted Solution

by:rgn2121
rgn2121 earned 100 total points
ID: 35072276
Actually...that might not exist at all...You will have to use MessageBox.Show(), which is the .Net version
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 52

Accepted Solution

by:
Carl Tawn earned 400 total points
ID: 35072311
It is in there. Have you actually added a reference the the Microsoft.VisualBasic assembly, or have you only imported the namespace?
0
 
LVL 12

Expert Comment

by:rgn2121
ID: 35072351
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
 
LVL 4

Author Closing Comment

by:Richard_XP
ID: 35072357
you are right, I need to add reference to microsoft.visualbasic first, then I can refer it. I will use messagebox instead
0
 
LVL 12

Expert Comment

by:rgn2121
ID: 35072382
I stand corrected...Microsoft.VisualBasic.MsgBoxStyle is there... I still don't see MsgBox
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now