Solved

Expression is a value and therefore cannot be the target of an assignment  vb.net

Posted on 2010-08-18
4
757 Views
Last Modified: 2013-11-27
Public Structure _cache
    Public loading As Boolean
End Structure


Public Class Server
    Public _cache_List As New List(Of _cache)()
...

For index As Int16 = 0 To _cache_List.Count - 1
_cache_List(index).loading = false '--> error
Next

"Expression is a value and therefore cannot be the target of an assignment "

what was wrong in the code above?
0
Comment
Question by:JSW21
  • 2
  • 2
4 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 33469523
The problem is that you are making an indirect reference to a Value-type (your structure) which results in it being classed as an expression.
You will have to declare a variable to hold a direct reference to the item and assign through that:


For index As Int16 = 0 To _cache_List.Count - 1
   Dim item As _cache = _cache_list(index)
   item.loading = false
Next

Open in new window

0
 

Author Comment

by:JSW21
ID: 33471957
Hi there
So I change the Structure into Class and it works.
I didnt know using structure will have different from class.

Do you think i am doing the right thing.
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 33472597
Structures are fundamentally different from classes in that they are value-types rather than reference types. Whether or not you need a struct rather than a class depends largely on its intended use.
0
 

Author Closing Comment

by:JSW21
ID: 33479653
I will need to use class as I need to modify its values.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

726 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