Solved

Converting one line from c# to vb.net

Posted on 2004-04-16
8
731 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
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

When you work with shopping cart / ecommerce relates web sites, you need to pass the certain form post details to the payment gateway process page with required details for the products items you give to order. Also you may need to track the ordered…
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 the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

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