473,399 Members | 4,192 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,399 software developers and data experts.

Problem assigning a value

Hello people,

We have been dealing with for a long time now. It's a bit weird for a
newcomer like us so we decided to ask the geniuses here.

C# doesn't seem to be assigning values, consider the lines of codes below:

------------------------------------------------
using Sem = semantics.SemanticsProcessingClass;
------------------------------------------------

//We created an instance of the class
Sem MySem = new Sem();

//This is where the problem is
string semSuggWords = MySem.fileContent;
----------------------------------------------

The value of the fileContent is not being stored. We have tried different
approaches and still no values. The debugger is telling us that it is "out
of scope".

Even a simple value assignment like this doesn't seem to work: string
semSuggWords = "test";

One solution we which indeed fixed it and finally made it possible to assign
a value to the newly created variable is declare it as a class field. Weird,
it would mean we have to declare all vars as fields.

Anyone encountered this problem?

Thanks in advanced.

Best,
Ricardo Sta. Rita
Nov 16 '05 #1
8 1675
Ricardo,

I find it hard to believe that something so simple doesn't work, and
yet, I can't think of a situation where it wouldn't. Can you post an
example of what you are trying to do? My only thought is that you are
declaring MySem on the class level, as well as semSuggWords. If this is the
case, then you can't do it, because you can't guarantee the order in which
MySem and semSuggWords are going to be initialized.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ricardo Sta. Rita" <vo*****@gmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hello people,

We have been dealing with for a long time now. It's a bit weird for a
newcomer like us so we decided to ask the geniuses here.

C# doesn't seem to be assigning values, consider the lines of codes below:

------------------------------------------------
using Sem = semantics.SemanticsProcessingClass;
------------------------------------------------

//We created an instance of the class
Sem MySem = new Sem();

//This is where the problem is
string semSuggWords = MySem.fileContent;
----------------------------------------------

The value of the fileContent is not being stored. We have tried different
approaches and still no values. The debugger is telling us that it is "out
of scope".

Even a simple value assignment like this doesn't seem to work: string
semSuggWords = "test";

One solution we which indeed fixed it and finally made it possible to
assign
a value to the newly created variable is declare it as a class field.
Weird,
it would mean we have to declare all vars as fields.

Anyone encountered this problem?

Thanks in advanced.

Best,
Ricardo Sta. Rita

Nov 16 '05 #2
Ricardo Sta. Rita <vo*****@gmail.com> wrote:
We have been dealing with for a long time now. It's a bit weird for a
newcomer like us so we decided to ask the geniuses here.
C# doesn't seem to be assigning values, consider the lines of codes below:


Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3
Hello again,

Below is the short but complete program that I think will help you
understand the problem
================================================== =======
using Sem = semantics.SemanticsProcessingClass;
namespace ElectronicWriter;
public class MainWriterProc : Page
{

public void MainProcess(object sender, System.EventArgs e)
{
Sem MySem = new Sem();
MySem.SetValue(myWords,myTopic,myType,myPath); //
We made sure that the object will

// start processing data and assign values

// to all the fields

string semSuggWords = MySem.fileContent;
// fileContent is a public string field

// in Sem class.
}

}

================================================== =======

Wierd part here is that "semSuggWords" is not recieving any values. Any
clues?
Another thing, this problem occured only after we started using DllImport in
our program, which I know will not, in any way, affect the MainProcess.

I don't know if it's just us or it's a bug.

Thanks for the help....
Ricardo
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Ricardo Sta. Rita <vo*****@gmail.com> wrote:
We have been dealing with for a long time now. It's a bit weird for a
newcomer like us so we decided to ask the geniuses here.
C# doesn't seem to be assigning values, consider the lines of codes
below:
Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:%2****************@tk2msftngp13.phx.gbl... Ricardo,

I find it hard to believe that something so simple doesn't work, and
yet, I can't think of a situation where it wouldn't. Can you post an
example of what you are trying to do? My only thought is that you are
declaring MySem on the class level, as well as semSuggWords. If this is the case, then you can't do it, because you can't guarantee the order in which
MySem and semSuggWords are going to be initialized.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

Nov 16 '05 #4
Ricardo Sta. Rita <vo*****@gmail.com> wrote:
Below is the short but complete program that I think will help you


It's short, but it's not complete.

See http://www.pobox.com/~skeet/csharp/incomplete.html

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #5
Hello jon,

I think what I posted is enough to let you know what the problem I'm having.

Consider this lines of codes:

string myStringTest = "";
myStringTest = "test";
myStringTest = "hello";

Although it's not a complete code, you know that I created a string named
"myStringTest" and tried assigning values to it 3 times. Problem is, the
values doesn't seem to get assigned to.

Thanks

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Ricardo Sta. Rita <vo*****@gmail.com> wrote:
Below is the short but complete program that I think will help you


It's short, but it's not complete.

See http://www.pobox.com/~skeet/csharp/incomplete.html

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #6
Ricardo Sta. Rita <vo*****@gmail.com> wrote:
I think what I posted is enough to let you know what the problem I'm
having.
Don't you think I'm a better judge of what I need to understand your
problem than you are?
Consider this lines of codes:

string myStringTest = "";
myStringTest = "test";
myStringTest = "hello";

Although it's not a complete code, you know that I created a string
named "myStringTest" and tried assigning values to it 3 times.
Problem is, the values doesn't seem to get assigned to.


They do in that case. You've clearly got something wrong in the code
you're not posting. Until you post it, we can't tell what it is.

So, for the third time: please post complete code.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #7
Thanks anyway...
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Ricardo Sta. Rita <vo*****@gmail.com> wrote:
I think what I posted is enough to let you know what the problem I'm
having.


Don't you think I'm a better judge of what I need to understand your
problem than you are?
Consider this lines of codes:

string myStringTest = "";
myStringTest = "test";
myStringTest = "hello";

Although it's not a complete code, you know that I created a string
named "myStringTest" and tried assigning values to it 3 times.
Problem is, the values doesn't seem to get assigned to.


They do in that case. You've clearly got something wrong in the code
you're not posting. Until you post it, we can't tell what it is.

So, for the third time: please post complete code.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #8
"Ricardo Sta. Rita" <vo*****@gmail.com> wrote in message news:<ug**************@TK2MSFTNGP09.phx.gbl>...
Hello again,

Below is the short but complete program that I think will help you
understand the problem
================================================== =======
using Sem = semantics.SemanticsProcessingClass;
namespace ElectronicWriter;
public class MainWriterProc : Page
{

public void MainProcess(object sender, System.EventArgs e)
{
Sem MySem = new Sem();
MySem.SetValue(myWords,myTopic,myType,myPath); //
We made sure that the object will

// start processing data and assign values

// to all the fields

string semSuggWords = MySem.fileContent;
// fileContent is a public string field

// in Sem class.
}

}


I've seen this before. First, it's clear that you can *never* know
whether sumSuggWords ever gets assigned a value, because you never
*do* anything with it, and it's not returned from the method. So, I'm
guessing that you're looking at the string in the debugger. Well, the
compiler is smart; it realizes that the string is never used, and does
not include it in the compiled IL. It's optimized right out. That's
why the debugger tells you that it's out of scope: it never existed,
so it was never in scope.

Look at the compiled method in a disassembler or decompiler like
Reflector to see what I mean. Then do something with the string after
it's assigned, like Debug.WriteLine(sumSuggWords), to see the string
pop back into the IL.

(It's impossible to know for sure if this is what you're running into
without, as Jon's asking for, a complete program. The reason he asks
for that, btw, is so that both you and he can be sure you're running
exactly the same code when debugging the problem, and that the problem
does not lie elsewhere. Also, it helps the debugging process to
isolate the problem from the rest of your code.)
Nov 16 '05 #9

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

Similar topics

1
by: Jenny | last post by:
Hi, Can I create an array of tags by assigning same name to these tags? For example, I have two <p> tags with the same name t1. But document.all.b.value=document.all.t.length does not...
17
by: Jon Slaughter | last post by:
I'm having a little trouble understanding what the slicing problem is. In B.S.'s C++ PL3rdEd he says "Becayse the Employee copy functions do not know anything about Managers, only the Employee...
12
by: gg.WS | last post by:
Hi I have a form with 140 labels. Each label has got an OnClick event that is different for each of these labels. Now I want to use the form as a subform of an other form. For this reason I have...
4
by: Mr. x | last post by:
Hello, I have declared in my program (*.aspx) something like this : <%@ Page Language="VB" Debug="true" %> .... <% dim current_view_page current_view_page = "1"
14
by: mauri1106 | last post by:
Hi, I have a little problem with a pointer. In my project is included an ".h" file with this declaration: "#define pMDMA_D0_START_ADDR ((void * volatile *)MDMA_D0_START_ADDR)" If I assign a...
3
by: Lalatendu Das | last post by:
Hi , Any way i have problem related to pointer let's say i have a double pointer like node_t **headptr =NULL ; //global one // let's say this is the defination of node_t typedef struct list {...
3
by: IvaPopova | last post by:
Hello, Consider this use strict; use Data::Dumper; my %hash1=(a=>, b=>, c=>,);
9
by: crater | last post by:
The following function is not updating an image in opera 9.02. upd_on = new Image() upd_on.src = "images/update_button.gif" function enableUpdate() { var update =...
14
by: abhishekkarnik | last post by:
Hi, I am trying to read an exe file and print it out character by character in hexadecimal format. The file goes something like this in hexadecimal 0x4d 0x5a 0x90 0x00 0x03 .... so on When I...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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
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.