Solved

Converting one line from c# to vb.net

Posted on 2004-04-16
8
743 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
Technology Partners: 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!

 
LVL 1

Author Comment

by:EugeneTrukhin
ID: 10845110
no it doesnt work because Ctype expects an expression and the type.
0
 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
RSS Feeds--IE 13 189
Windows Standards for file storage. 3 36
Tech Writing Terminology - Pane or Panel? 8 119
php mysql check email already in database. (second check) 7 106
Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

733 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