Solved

Converting one line from c# to vb.net

Posted on 2004-04-16
8
752 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

 
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

Industry Leaders: 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!

Question has a verified solution.

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

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…
Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

726 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