473,385 Members | 1,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

type cannot be used as an expression

Hi

I tried to convert the following C# code to vb.net.

code in C#
__________________________________________________ ______________
using System;
using System.Reflection;
using System.Resources;

namespace LivingObjects.Resources
{
/// <summary>
/// This Class is used to create the ResourceManager for the site.
/// It manages a single instance of this object.
/// </summary>
internal class ResourceFactory
{
/// <summary>
/// Private Contructor. This factory is a static implementation.
/// It cannot be instanciated.
/// </summary>
private ResourceFactory()
{
}

private static ResourceManager _rm;

public static ResourceManager ResourceManager
{
get
{
if(_rm == null)
{
lock(typeof(LivingObjects.Resources.ResourceFactor y))
{
if(_rm == null)
{
string resxNamespace =
typeof(LivingObjects.Resources.ResourceFactory).Na mespace;
_rm = new ResourceManager(resxNamespace + ".Labels",
System.Reflection.Assembly.GetExecutingAssembly()) ;
}
}
}
return _rm;
}
}

public static string GetLabel(string resourceID)
{
return ResourceManager.GetString(resourceID);
}
}
}
__________________________________________________ _______________________

code in VB.Net
__________________________________________________ _______________________
Imports System
Imports System.Reflection
Imports System.Resources

Namespace LivingObjects.Resources

' This Class is used to create the ResourceManager for the site.
' It manages a single instance of this object.

Friend Class ResourceFactory

' Private Contructor. This factory is a static implementation.
' It cannot be instanciated.
Private Sub New()
End Sub

Private Shared _rm As ResourceManager

Public Shared ReadOnly Property ResourceManager() As
ResourceManager
Get
If _rm Is Nothing Then
Lock(Type.GetType(LivingObjects.Resources.Resource Factory))
If _rm Is Nothing Then
Dim resxNamespace As String =
Type.GetType(LivingObjects.Resources.ResourceFacto ry).Namespace
_rm = New ResourceManager(resxNamespace +
".Labels", System.Reflection.Assembly.GetExecutingAssembly())
End If
Unlock(Type.GetType(LivingObjects.Resources.Resour ceFactory))
End If
Return _rm
End Get
End Property

Public Shared Function GetLabel(ByVal resourceID As String) As
String
Return ResourceManager.GetString(resourceID)
End Function

End Class

End Namespace
__________________________________________________ ________________________

The error comes in vb.net whenever I use
'LivingObjects.Resources.ResourceFactory'.
The build error says: "'ResourceFactory' is a type in 'Resources' and
cannot be used as an expression."

How can it be implemented then in vb.net? any ideas?

Thanks,

Eelis

p.s. The C# code was created by Jonathan
Gauthier.(http://www.codetools.com/cs/miscctrl...emListView.asp)
Nov 21 '05 #1
4 34686
Try replacing Type.GetType with the GetType function:

GetType(LivingObjects.Resources.ResourceFactory)
instead of:
Type.GetType(LivingObjects.Resources.ResourceFacto ry)
Imran.

"eelis.net" <ee*****@yahoo.com> wrote in message
news:32**************************@posting.google.c om...
Hi

I tried to convert the following C# code to vb.net.

code in C#
__________________________________________________ ______________
using System;
using System.Reflection;
using System.Resources;

namespace LivingObjects.Resources
{
/// <summary>
/// This Class is used to create the ResourceManager for the site.
/// It manages a single instance of this object.
/// </summary>
internal class ResourceFactory
{
/// <summary>
/// Private Contructor. This factory is a static implementation.
/// It cannot be instanciated.
/// </summary>
private ResourceFactory()
{
}

private static ResourceManager _rm;

public static ResourceManager ResourceManager
{
get
{
if(_rm == null)
{
lock(typeof(LivingObjects.Resources.ResourceFactor y))
{
if(_rm == null)
{
string resxNamespace =
typeof(LivingObjects.Resources.ResourceFactory).Na mespace;
_rm = new ResourceManager(resxNamespace + ".Labels",
System.Reflection.Assembly.GetExecutingAssembly()) ;
}
}
}
return _rm;
}
}

public static string GetLabel(string resourceID)
{
return ResourceManager.GetString(resourceID);
}
}
}
__________________________________________________ _______________________

code in VB.Net
__________________________________________________ _______________________
Imports System
Imports System.Reflection
Imports System.Resources

Namespace LivingObjects.Resources

' This Class is used to create the ResourceManager for the site.
' It manages a single instance of this object.

Friend Class ResourceFactory

' Private Contructor. This factory is a static implementation.
' It cannot be instanciated.
Private Sub New()
End Sub

Private Shared _rm As ResourceManager

Public Shared ReadOnly Property ResourceManager() As
ResourceManager
Get
If _rm Is Nothing Then
Lock(Type.GetType(LivingObjects.Resources.Resource Factory)) If _rm Is Nothing Then
Dim resxNamespace As String =
Type.GetType(LivingObjects.Resources.ResourceFacto ry).Namespace
_rm = New ResourceManager(resxNamespace +
".Labels", System.Reflection.Assembly.GetExecutingAssembly())
End If
Unlock(Type.GetType(LivingObjects.Resources.Resour ceFactory)) End If
Return _rm
End Get
End Property

Public Shared Function GetLabel(ByVal resourceID As String) As
String
Return ResourceManager.GetString(resourceID)
End Function

End Class

End Namespace
__________________________________________________ ________________________

The error comes in vb.net whenever I use
'LivingObjects.Resources.ResourceFactory'.
The build error says: "'ResourceFactory' is a type in 'Resources' and
cannot be used as an expression."

How can it be implemented then in vb.net? any ideas?

Thanks,

Eelis

p.s. The C# code was created by Jonathan
Gauthier.(http://www.codetools.com/cs/miscctrl...emListView.asp)

Nov 21 '05 #2
Hi again

That didn't work either. It makes a build error described as:
"value of type 'System.Type' cannot be converted to 'Integer'" for the
whole expression (GetType(LivingObjects.Resources.ResourceFactory)) .

Any other ideas...

Thanks a lot!

eelis

"Imran Koradia" <no****@microsoft.com> wrote in message news:<OG**************@TK2MSFTNGP11.phx.gbl>...
Try replacing Type.GetType with the GetType function:

GetType(LivingObjects.Resources.ResourceFactory)
instead of:
Type.GetType(LivingObjects.Resources.ResourceFacto ry)
Imran.

Nov 21 '05 #3

"eelis.net" <ee*****@yahoo.com> wrote
That didn't work either. It makes a build error described as:
"value of type 'System.Type' cannot be converted to 'Integer'" for the
whole expression (GetType(LivingObjects.Resources.ResourceFactory)) .

Any other ideas...

How about

LivingObjects.Resources.ResourceFactory.GetType.Na mespace
The docs say GetType expects a string, at best you're giving it
an object. If the above doesn't work, try passing it a string with
that full name in it.

HTH
LFS

Nov 21 '05 #4
Sorry for the late reply - my outlook express is way out of whack with
message threads.

Anyway, the 'lock' in C# and VB.NET mean different things. Here's how your
VB.NET code should look like:

Imports System
Imports System.Reflection
Imports System.Resources

Namespace LivingObjects.Resources

' This Class is used to create the ResourceManager for the site.
' It manages a single instance of this object.

Friend Class ResourceFactory

' Private Contructor. This factory is a static implementation.
' It cannot be instanciated.
Private Sub New()
End Sub

Private Shared _rm As ResourceManager

Public Shared ReadOnly Property _
ResourceManager() As ResourceManager
Get
If _rm Is Nothing Then
SyncLock GetType( _
LivingObjects.Resources.ResourceFactory)
If _rm Is Nothing Then
Dim resxNamespace As String = _
GetType( _

LivingObjects.Resources.ResourceFactory).Namespace
_rm = New ResourceManager(resxNamespace + ".Labels",
_

System.Reflection.Assembly.GetExecutingAssembly())
End If
End SyncLock
End If
Return _rm
End Get
End Property

Public Shared Function GetLabel( _
ByVal resourceID As String) As String
Return ResourceManager.GetString(resourceID)
End Function

End Class

End Namespace
hope that helps..
Imran.

"eelis.net" <ee*****@yahoo.com> wrote in message
news:32**************************@posting.google.c om...
Hi again

That didn't work either. It makes a build error described as:
"value of type 'System.Type' cannot be converted to 'Integer'" for the
whole expression (GetType(LivingObjects.Resources.ResourceFactory)) .

Any other ideas...

Thanks a lot!

eelis

"Imran Koradia" <no****@microsoft.com> wrote in message

news:<OG**************@TK2MSFTNGP11.phx.gbl>...
Try replacing Type.GetType with the GetType function:

GetType(LivingObjects.Resources.ResourceFactory)
instead of:
Type.GetType(LivingObjects.Resources.ResourceFacto ry)
Imran.

Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Batista, Facundo | last post by:
Here I send it. Suggestions and all kinds of recomendations are more than welcomed. If it all goes ok, it'll be a PEP when I finish writing/modifying the code. Thank you. .. Facundo
51
by: jacob navia | last post by:
I would like to add at the beginning of the C tutorial I am writing a short blurb about what "types" are. I came up with the following text. Please can you comment? Did I miss something? Is...
59
by: Michael C | last post by:
eg void DoIt() { int i = FromString("1"); double d = FromString("1.1"); } int FromString(string SomeValue) {
0
by: eelis.net | last post by:
Hi I tried to convert the following C# code to vb.net. code in C# ________________________________________________________________ using System; using System.Reflection; using...
1
by: Angel Tsankov | last post by:
Does the C++ standard define what should happen if the size of int in the following code cannot accommodate the bit field? struct bit_fields { unsigned int digit:17; // int is 16 bits };
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
4
by: zaeminkr | last post by:
I got a good answer here I have still confusing part. I have two very simple classes class DRect { private : double x0, y0, x1, y1; public : DRect(double a, double b, double c, double d) :...
8
by: minseokoh | last post by:
Hi, Could someone explain why "const" is located after the function name and what it means? inline unsigned char *access(int off) const { if (off < 0) abort(); return (&bits_); }
0
by: Anonymous | last post by:
Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <wfednQ6STZz2Z6faRVnytAA@bt.com> Lines: 15 X-Usenet-Provider: http://www.giganews.com...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.