By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,190 Members | 784 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,190 IT Pros & Developers. It's quick & easy.

Name/Value Properties

P: n/a
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
Share this Question
Share on Google+
6 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.