473,666 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Name/Value Properties

Hello,

Does anyone have any ideas how I can accomplish this using properties. I'm
trying to create a property, that acts like a structure. Basically I'm
trying to create a property that I could do this with.

myCompanyIndex = currentCompany. Index
myCompanyName = currentCompany. Value

"currentCompany " would be the property, Index is an integer, Value is a
string.

Here is some of what I've tried...(I'm trying to set a single session
variable in asp.net, but for people unfamiliar with asp.net,
Session("compan y") would be an object)

Protected Structure NameValue
Public Name As String
Public Value As Integer
End Structure

Protected Property currentCompany( ) As NameValue
Get
currentCompany = CType(Session(" company"), NameValue)
End Get
Set(ByVal Value As NameValue)
Session("compan y") = Value
End Set
End Property

This looks like it may work, but in code when I try this I get the following
error.

currentPEO.valu e = 1
currentPEO.Name = "My Company Name"

I get the following error on both lines..."Expres sion is a value and
therefore cannot be the target of an assignment."

Any help?
--Michael
Nov 20 '05 #1
6 1256
Raterus:

Looks like Boxing.... instead of using a struct, change it to a class..that
should fix it.
"Raterus" <raterus@localh ost> wrote in message
news:ex******** ******@TK2MSFTN GP12.phx.gbl...
Hello,

Does anyone have any ideas how I can accomplish this using properties. I'm trying to create a property, that acts like a structure. Basically I'm
trying to create a property that I could do this with.

myCompanyIndex = currentCompany. Index
myCompanyName = currentCompany. Value

"currentCompany " would be the property, Index is an integer, Value is a
string.

Here is some of what I've tried...(I'm trying to set a single session
variable in asp.net, but for people unfamiliar with asp.net,
Session("compan y") would be an object)

Protected Structure NameValue
Public Name As String
Public Value As Integer
End Structure

Protected Property currentCompany( ) As NameValue
Get
currentCompany = CType(Session(" company"), NameValue)
End Get
Set(ByVal Value As NameValue)
Session("compan y") = Value
End Set
End Property

This looks like it may work, but in code when I try this I get the following error.

currentPEO.valu e = 1
currentPEO.Name = "My Company Name"

I get the following error on both lines..."Expres sion is a value and
therefore cannot be the target of an assignment."

Any help?
--Michael

Nov 20 '05 #2
Sure did thanks! I also had to make the varibles in that class "shared", or
it wouldn't be instantiated. It seems every time I try to use a structure I
end up using a class, any point really now to use a structure over a class?

"William Ryan eMVP" <do********@com cast.nospam.net > wrote in message
news:e1******** **********@tk2m sftngp13.phx.gb l...
Raterus:

Looks like Boxing.... instead of using a struct, change it to a class..that should fix it.
"Raterus" <raterus@localh ost> wrote in message
news:ex******** ******@TK2MSFTN GP12.phx.gbl...
Hello,

Does anyone have any ideas how I can accomplish this using properties.

I'm
trying to create a property, that acts like a structure. Basically I'm
trying to create a property that I could do this with.

myCompanyIndex = currentCompany. Index
myCompanyName = currentCompany. Value

"currentCompany " would be the property, Index is an integer, Value is a
string.

Here is some of what I've tried...(I'm trying to set a single session
variable in asp.net, but for people unfamiliar with asp.net,
Session("compan y") would be an object)

Protected Structure NameValue
Public Name As String
Public Value As Integer
End Structure

Protected Property currentCompany( ) As NameValue
Get
currentCompany = CType(Session(" company"), NameValue)
End Get
Set(ByVal Value As NameValue)
Session("compan y") = Value
End Set
End Property

This looks like it may work, but in code when I try this I get the

following
error.

currentPEO.valu e = 1
currentPEO.Name = "My Company Name"

I get the following error on both lines..."Expres sion is a value and
therefore cannot be the target of an assignment."

Any help?
--Michael


Nov 20 '05 #3
Nope, using "shared" in the NameValue class isn't going to work. I need
some way to instantiate these properties so they use different
"NameValue" 's. Here's what I got

Public Class NameValue
Public Name As String
Public Value As Integer

Public Sub New()
Name = String.Empty
Value = -1
End Sub
End Class

Pubic Class Common
Protected Property currentCompany( ) As NameValue
Get
currentCompany = CType(Session(" Company"), NameValue)
End Get
Set(ByVal Value As NameValue)
Session("Compan y") = Value
End Set
End Property
End Class

then from another class that inherits common:

currentCompany. Value = 6
which gives the good ole error "Object reference not set to an instance of
an object."
I don't know how I am supposed to issue a "new" when it isn't necessarily
new. I think I'm trying to do something I really should be doing...
"Raterus" <raterus@localh ost> wrote in message
news:%2******** **********@TK2M SFTNGP11.phx.gb l...
Sure did thanks! I also had to make the varibles in that class "shared", or it wouldn't be instantiated. It seems every time I try to use a structure I end up using a class, any point really now to use a structure over a class?
"William Ryan eMVP" <do********@com cast.nospam.net > wrote in message
news:e1******** **********@tk2m sftngp13.phx.gb l...
Raterus:

Looks like Boxing.... instead of using a struct, change it to a

class..that
should fix it.
"Raterus" <raterus@localh ost> wrote in message
news:ex******** ******@TK2MSFTN GP12.phx.gbl...
Hello,

Does anyone have any ideas how I can accomplish this using properties.

I'm
trying to create a property, that acts like a structure. Basically I'm
trying to create a property that I could do this with.

myCompanyIndex = currentCompany. Index
myCompanyName = currentCompany. Value

"currentCompany " would be the property, Index is an integer, Value is a string.

Here is some of what I've tried...(I'm trying to set a single session
variable in asp.net, but for people unfamiliar with asp.net,
Session("compan y") would be an object)

Protected Structure NameValue
Public Name As String
Public Value As Integer
End Structure

Protected Property currentCompany( ) As NameValue
Get
currentCompany = CType(Session(" company"), NameValue)
End Get
Set(ByVal Value As NameValue)
Session("compan y") = Value
End Set
End Property

This looks like it may work, but in code when I try this I get the

following
error.

currentPEO.valu e = 1
currentPEO.Name = "My Company Name"

I get the following error on both lines..."Expres sion is a value and
therefore cannot be the target of an assignment."

Any help?
--Michael



Nov 20 '05 #4
You haven't shown where "currentPEO " is defined

"Raterus" <raterus@localh ost> wrote in message
news:ex******** ********@TK2MSF TNGP12.phx.gbl. ..
Hello,

Does anyone have any ideas how I can accomplish this using properties. I'm trying to create a property, that acts like a structure. Basically I'm
trying to create a property that I could do this with.

myCompanyIndex = currentCompany. Index
myCompanyName = currentCompany. Value

"currentCompany " would be the property, Index is an integer, Value is a
string.

Here is some of what I've tried...(I'm trying to set a single session
variable in asp.net, but for people unfamiliar with asp.net,
Session("compan y") would be an object)

Protected Structure NameValue
Public Name As String
Public Value As Integer
End Structure

Protected Property currentCompany( ) As NameValue
Get
currentCompany = CType(Session(" company"), NameValue)
End Get
Set(ByVal Value As NameValue)
Session("compan y") = Value
End Set
End Property

This looks like it may work, but in code when I try this I get the following error.

currentPEO.valu e = 1
currentPEO.Name = "My Company Name"

I get the following error on both lines..."Expres sion is a value and
therefore cannot be the target of an assignment."

Any help?
--Michael

Nov 20 '05 #5
Raterus:

No need to use Shared in this case. Your private member variable, has it
been initialized? I'm guessing no due to the exception. So, when you
create a new instance of Common set currentCompany = new NameValue and that
should get you around the problem.

I use Structs a fair amount when I need to pass something around but
Boxing/Unboxing can be a performance problem in addition to being a big
headache if you aren't careful.

One way or another, you'll need to instantiate an instance of NameValue and
you should be ok...let me know if not.

Bill
"Raterus" <raterus@localh ost> wrote in message
news:eI******** ******@tk2msftn gp13.phx.gbl...
Nope, using "shared" in the NameValue class isn't going to work. I need
some way to instantiate these properties so they use different
"NameValue" 's. Here's what I got

Public Class NameValue
Public Name As String
Public Value As Integer

Public Sub New()
Name = String.Empty
Value = -1
End Sub
End Class

Pubic Class Common
Protected Property currentCompany( ) As NameValue
Get
currentCompany = CType(Session(" Company"), NameValue)
End Get
Set(ByVal Value As NameValue)
Session("Compan y") = Value
End Set
End Property
End Class

then from another class that inherits common:

currentCompany. Value = 6
which gives the good ole error "Object reference not set to an instance of
an object."
I don't know how I am supposed to issue a "new" when it isn't necessarily
new. I think I'm trying to do something I really should be doing...
"Raterus" <raterus@localh ost> wrote in message
news:%2******** **********@TK2M SFTNGP11.phx.gb l...
Sure did thanks! I also had to make the varibles in that class "shared",
or
it wouldn't be instantiated. It seems every time I try to use a
structure I
end up using a class, any point really now to use a structure over a class?

"William Ryan eMVP" <do********@com cast.nospam.net > wrote in message
news:e1******** **********@tk2m sftngp13.phx.gb l...
Raterus:

Looks like Boxing.... instead of using a struct, change it to a

class..that
should fix it.
"Raterus" <raterus@localh ost> wrote in message
news:ex******** ******@TK2MSFTN GP12.phx.gbl...
> Hello,
>
> Does anyone have any ideas how I can accomplish this using properties. I'm
> trying to create a property, that acts like a structure. Basically I'm > trying to create a property that I could do this with.
>
> myCompanyIndex = currentCompany. Index
> myCompanyName = currentCompany. Value
>
> "currentCompany " would be the property, Index is an integer, Value is a > string.
>
> Here is some of what I've tried...(I'm trying to set a single

session > variable in asp.net, but for people unfamiliar with asp.net,
> Session("compan y") would be an object)
>
> Protected Structure NameValue
> Public Name As String
> Public Value As Integer
> End Structure
>
> Protected Property currentCompany( ) As NameValue
> Get
> currentCompany = CType(Session(" company"), NameValue)
> End Get
> Set(ByVal Value As NameValue)
> Session("compan y") = Value
> End Set
> End Property
>
> This looks like it may work, but in code when I try this I get the
following
> error.
>
> currentPEO.valu e = 1
> currentPEO.Name = "My Company Name"
>
> I get the following error on both lines..."Expres sion is a value and
> therefore cannot be the target of an assignment."
>
> Any help?
> --Michael
>
>



Nov 20 '05 #6
I tried adding a New() Sub to my common class, and instantiating my
properties there, but then I run into an asp.net issue. My base pages
inherit this Common class which then inherits the Page Class. At the time
this happens, my session object isn't instantiated, so I get an error
"Session state can only be used when enableSessionSt ate is set to true,
either in a configuration file or in the Page directive"

I can work around this by just adding a sub to the common class "Start()",
which instantiates my properties, and then calling it from Page_load. I
didn't really like that option though, as it required me to do that on every
page. Sure it's not that big of a deal though, i'd just much rather use
them right off the bat, than do all this instantiating :).

Any other options you can think of?
--Michael

"William Ryan eMVP" <do********@com cast.nospam.net > wrote in message
news:%2******** **********@TK2M SFTNGP11.phx.gb l...
Raterus:

No need to use Shared in this case. Your private member variable, has it
been initialized? I'm guessing no due to the exception. So, when you
create a new instance of Common set currentCompany = new NameValue and that should get you around the problem.

I use Structs a fair amount when I need to pass something around but
Boxing/Unboxing can be a performance problem in addition to being a big
headache if you aren't careful.

One way or another, you'll need to instantiate an instance of NameValue and you should be ok...let me know if not.

Bill
"Raterus" <raterus@localh ost> wrote in message
news:eI******** ******@tk2msftn gp13.phx.gbl...
Nope, using "shared" in the NameValue class isn't going to work. I need
some way to instantiate these properties so they use different
"NameValue" 's. Here's what I got

Public Class NameValue
Public Name As String
Public Value As Integer

Public Sub New()
Name = String.Empty
Value = -1
End Sub
End Class

Pubic Class Common
Protected Property currentCompany( ) As NameValue
Get
currentCompany = CType(Session(" Company"), NameValue)
End Get
Set(ByVal Value As NameValue)
Session("Compan y") = Value
End Set
End Property
End Class

then from another class that inherits common:

currentCompany. Value = 6
which gives the good ole error "Object reference not set to an instance of
an object."
I don't know how I am supposed to issue a "new" when it isn't necessarily new. I think I'm trying to do something I really should be doing...
"Raterus" <raterus@localh ost> wrote in message
news:%2******** **********@TK2M SFTNGP11.phx.gb l...
Sure did thanks! I also had to make the varibles in that class

"shared",
or
it wouldn't be instantiated. It seems every time I try to use a

structure
I
end up using a class, any point really now to use a structure over a

class?

"William Ryan eMVP" <do********@com cast.nospam.net > wrote in message
news:e1******** **********@tk2m sftngp13.phx.gb l...
> Raterus:
>
> Looks like Boxing.... instead of using a struct, change it to a
class..that
> should fix it.
> "Raterus" <raterus@localh ost> wrote in message
> news:ex******** ******@TK2MSFTN GP12.phx.gbl...
> > Hello,
> >
> > Does anyone have any ideas how I can accomplish this using

properties. > I'm
> > trying to create a property, that acts like a structure. Basically I'm > > trying to create a property that I could do this with.
> >
> > myCompanyIndex = currentCompany. Index
> > myCompanyName = currentCompany. Value
> >
> > "currentCompany " would be the property, Index is an integer, Value is
a
> > string.
> >
> > Here is some of what I've tried...(I'm trying to set a single

session > > variable in asp.net, but for people unfamiliar with asp.net,
> > Session("compan y") would be an object)
> >
> > Protected Structure NameValue
> > Public Name As String
> > Public Value As Integer
> > End Structure
> >
> > Protected Property currentCompany( ) As NameValue
> > Get
> > currentCompany = CType(Session(" company"), NameValue)
> > End Get
> > Set(ByVal Value As NameValue)
> > Session("compan y") = Value
> > End Set
> > End Property
> >
> > This looks like it may work, but in code when I try this I get the
> following
> > error.
> >
> > currentPEO.valu e = 1
> > currentPEO.Name = "My Company Name"
> >
> > I get the following error on both lines..."Expres sion is a value and > > therefore cannot be the target of an assignment."
> >
> > Any help?
> > --Michael
> >
> >
>
>



Nov 20 '05 #7

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

Similar topics

2
3317
by: Wayne Taylor | last post by:
Hello all I'm trying to write a liitle application to add users to AD, when I'm trying to add a user and a group (example code from the SDK)..... I get the following error: A constraint violation occurred. I think it may be something to do with access writes, I'm not sure... I'm logged in as system admin on my lab network.... I'm off to try and sort this
1
29204
by: Prasad Karunakaran | last post by:
I am using the C# DirectoryEntry class to retrieve the Properties of an user object in the Active Directory. I need to get the First Name and Last Name as properties. I know it is not supported with the ADSI NT Provider and only supported in the LDAP Provider. So given an UserId (UID) how can I read the First Name and Last Name using LDAP Provider. If anybody can help me with a C# sample code it would of great help. Thanks in advance.
11
3018
by: Andrew Thompson | last post by:
I have written a few scripts to parse the URL arguments and either list them or allow access to the value of any parameter by name. <http://www.physci.org/test/003url/index.html> <http://www.physci.org/test/003url/index.html?url=http://mybiz.com/&that=this&when=now#21> <http://www.physci.org/test/003url/index.html?url=http://mybiz.com/&when=now> Before I go offering it in public (and writing it into any number of the 'development kits'...
1
5051
by: Prasad Karunakaran | last post by:
I am using the C# DirectoryEntry class to retrieve the Properties of an user object in the Active Directory. I need to get the First Name and Last Name as properties. I know it is not supported with the ADSI NT Provider and only supported in the LDAP Provider. So given an UserId (UID) how can I read the First Name and Last Name using LDAP Provider. If anybody can help me with a C# sample code it would of great help. Thanks in advance.
20
6957
by: weston | last post by:
I've got a piece of code where, for all the world, it looks like this fails in IE 6: hometab = document.getElementById('hometab'); but this succeeds: hometabemt = document.getElementById('hometab'); Has anyone ever seen anything like this before, or am I dreaming?
1
2524
by: mehdi_mousavi | last post by:
Hi folks, Consider a string that's defined under VS2005 resource editor as myField with the value of myValue. To access the value, I could easily use the Properties.Resources class, for example: global::myNameSpace.Properties.Resources.myField However, I would like to retreive it's string representation of the field's name, i.e., the "myField". How am I supposed to do that?
0
2693
by: =?Utf-8?B?U2ltb25EZXY=?= | last post by:
Hi All I would like to install the same Windows Service project on the same server under different names, one for each customer. I have been able to do it but I would like an expert opinion as to whether my solution is robust or whether there is a better way to do it. What I've been trying to do is to create a core project with different extension projects, one for each customer. I wanted to create a different Setup project for each...
10
9665
by: =?Utf-8?B?SmFtZXMgV29uZw==?= | last post by:
Hi everybody, I'm trying to use the new VB 2008 right now and I want to know how to preset the company name and copyright informtion in Assembly Information. In my current VB 2005, company name and copyright information (the word "CopyRight" with company name and year) is filled in automatically once a new project is created. However, I have no idea where I can configurate it in my new VB 2008. Thanks for your kindly advice!
2
2684
by: lairpr74 | last post by:
I am trying to update the managers name in active directory with an application I got that updates active directory. I been strugling with this for a few weeks now and couldn't find the best way to update the managers name. I got a datareader that returns all the employees from the database then a method checks each one of the records and compares them in AD and them commits the changes to the users information. This is what I have try...
0
8444
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8356
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8869
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8781
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8639
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7386
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6198
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
2771
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1775
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.