?
Solved

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

Posted on 2010-08-18
4
Medium Priority
?
828 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

762 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