Solved

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

Posted on 2011-03-08
8
413 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

757 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

18 Experts available now in Live!

Get 1:1 Help Now