473,403 Members | 2,359 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,403 software developers and data experts.

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("company") 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("company") = Value
End Set
End Property

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

currentPEO.value = 1
currentPEO.Name = "My Company Name"

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

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

Looks like Boxing.... instead of using a struct, change it to a class..that
should fix it.
"Raterus" <raterus@localhost> wrote in message
news:ex**************@TK2MSFTNGP12.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("company") 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("company") = Value
End Set
End Property

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

currentPEO.value = 1
currentPEO.Name = "My Company Name"

I get the following error on both lines..."Expression 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********@comcast.nospam.net> wrote in message
news:e1******************@tk2msftngp13.phx.gbl...
Raterus:

Looks like Boxing.... instead of using a struct, change it to a class..that should fix it.
"Raterus" <raterus@localhost> wrote in message
news:ex**************@TK2MSFTNGP12.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("company") 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("company") = Value
End Set
End Property

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

following
error.

currentPEO.value = 1
currentPEO.Name = "My Company Name"

I get the following error on both lines..."Expression 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("Company") = 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@localhost> wrote in message
news:%2******************@TK2MSFTNGP11.phx.gbl...
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********@comcast.nospam.net> wrote in message
news:e1******************@tk2msftngp13.phx.gbl...
Raterus:

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

class..that
should fix it.
"Raterus" <raterus@localhost> wrote in message
news:ex**************@TK2MSFTNGP12.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("company") 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("company") = Value
End Set
End Property

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

following
error.

currentPEO.value = 1
currentPEO.Name = "My Company Name"

I get the following error on both lines..."Expression 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@localhost> wrote in message
news:ex****************@TK2MSFTNGP12.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("company") 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("company") = Value
End Set
End Property

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

currentPEO.value = 1
currentPEO.Name = "My Company Name"

I get the following error on both lines..."Expression 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@localhost> wrote in message
news:eI**************@tk2msftngp13.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("Company") = 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@localhost> wrote in message
news:%2******************@TK2MSFTNGP11.phx.gbl...
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********@comcast.nospam.net> wrote in message
news:e1******************@tk2msftngp13.phx.gbl...
Raterus:

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

class..that
should fix it.
"Raterus" <raterus@localhost> wrote in message
news:ex**************@TK2MSFTNGP12.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("company") 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("company") = Value
> End Set
> End Property
>
> This looks like it may work, but in code when I try this I get the
following
> error.
>
> currentPEO.value = 1
> currentPEO.Name = "My Company Name"
>
> I get the following error on both lines..."Expression 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 enableSessionState 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********@comcast.nospam.net> wrote in message
news:%2******************@TK2MSFTNGP11.phx.gbl...
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@localhost> wrote in message
news:eI**************@tk2msftngp13.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("Company") = 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@localhost> wrote in message
news:%2******************@TK2MSFTNGP11.phx.gbl...
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********@comcast.nospam.net> wrote in message
news:e1******************@tk2msftngp13.phx.gbl...
> Raterus:
>
> Looks like Boxing.... instead of using a struct, change it to a
class..that
> should fix it.
> "Raterus" <raterus@localhost> wrote in message
> news:ex**************@TK2MSFTNGP12.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("company") 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("company") = Value
> > End Set
> > End Property
> >
> > This looks like it may work, but in code when I try this I get the
> following
> > error.
> >
> > currentPEO.value = 1
> > currentPEO.Name = "My Company Name"
> >
> > I get the following error on both lines..."Expression 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
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...
1
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...
11
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>...
1
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...
20
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 =...
1
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:...
0
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...
10
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...
2
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...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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,...
0
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...

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.