Solved

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

Posted on 2011-03-08
8
419 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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
 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to sort a list of objects using an item in an enclosed list 5 46
Regex validation 2 24
Disable extension 8 38
get combo value in class 5 8
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
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 …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

777 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