Solved

Converting one line from c# to vb.net

Posted on 2004-04-16
8
717 Views
Last Modified: 2007-12-19
Hello,

I want to convert one simple c# line into vb.net and i can't do it. I don't know vb.net that much, and I spend some time searching on MSDN and I didnt find any samples.

protected ResourceManager LocRM;
LocRM= new ResourceManager("MyProject.Resources.ProjectControl", typeof(ProjectControl).Assembly);

And the purpose of this is to read data from my resource file which i have in /MyProject/Resources and which is called ProjectControl.resx

i did this:

Protected LocRM As ResourceManager
 and then the next line i cant convert...anyone can help?
0
Comment
Question by:EugeneTrukhin
  • 4
  • 2
  • 2
8 Comments
 
LVL 35

Expert Comment

by:YZlat
ID: 10843134
Protected LocRM As ResourceManager
LocRM=New ResourceManager("MyProject.Resources.ProjectControl", Me.GetType.Assembly)

or

Dim LocRM As ResourceManager = New ResourceManager("MyProject.Resources.ProjectControl", Me.GetType.Assembly)

0
 
LVL 1

Author Comment

by:EugeneTrukhin
ID: 10843239
Me.GetType.Assembly doesnt work because i want to read not from the resource file associated with that particular page but from another resource file which is stored in another directory. Me.GetType.Assembly --> Im getting an assembly associated with that particular page but I wanna read another assembly...

In c# it works LocRM= new ResourceManager("MyProject.Resources.ProjectControl", typeof(ProjectControl).Assembly); but this "typeof(ProjectControl).Assembly" part I dont know how to represent in vb.net
0
 
LVL 35

Expert Comment

by:YZlat
ID: 10844840
try  CType(ProjectControl).Assembly
0
 
LVL 1

Author Comment

by:EugeneTrukhin
ID: 10845110
no it doesnt work because Ctype expects an expression and the type.
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 3

Expert Comment

by:solublefish
ID: 10846875
I think
Type.GetType("ProjectControl").Assembly
should get you the Assembly associated with "ProjectControl", making the whole line:

Dim LocRM As ResourceManager = New ResourceManager("MyProject.Resources.ProjectControl", Type.GetType("ProjectControl").Assembly)

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemtypeclassgettypetopic.asp
0
 
LVL 1

Author Comment

by:EugeneTrukhin
ID: 10859351
I tried what you say but i get "Object reference not set to an instance of an object."....Hm, I wonder why it is so easy to do in c#, and i have so many problems with vb.net.

Does anyone have an experience reading stuff from the resource file based on the culture in vb.net?

0
 
LVL 3

Accepted Solution

by:
solublefish earned 125 total points
ID: 10862162
I don't think the problem is with reading the resource file - I suspect the ResourceManager will work fine once you pass it the right type. Your C# code works, so all you need to do is get the equivalent of typeof in VB.NET to get a Type object representing your ProjectControl. Unfortunately, VB.NET doesn't have a regular typeof operator, so you have to make do with GetType.

Try using the fully-qualified name of the ProjectControl type -Type.GetType("MyCompany.MyProduct.ProjectControl") or whatever:
Dim LocRM As ResourceManager = New ResourceManager("MyProject.Resources.ProjectControl", Type.GetType("MyCompany.MyProduct.ProjectControl").Assembly)


Or if it doesn't have any side effects, create a new ProjectControl object, and use the actual instance's .GetType() method:

Dim pc as ProjectControl
set pc = new ProjectControl()
Dim LocRM As ResourceManager = New ResourceManager("MyProject.Resources.ProjectControl", pc.GetType().Assembly)
0
 
LVL 1

Author Comment

by:EugeneTrukhin
ID: 10863262
This worked:

LocRM = New ResourceManager("MyProject.ProjectControl", Type.GetType("MyProject.ProjectControl.__ProjectControl").Assembly)

I guess i had a problem because in vb.net the namespaces are handled differently than in c#. I tried to define the path to the resource file using c# mentality. In vb.net it's done differently.

Thank you solublefish.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

744 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

10 Experts available now in Live!

Get 1:1 Help Now