473,462 Members | 1,350 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Odd assignment bug

VB.NET2005 WinXP SP2

I have some code that looks like:-

with _state
....
.data =GetData()
....
end with

where .data is a DataTable

this code has worked fine for 2 weeks

now however although GetData returns 15 rows .data always has rows.count =0

If I change the code to:-

with _state
....
_state.data =GetData()
....
end with

i.e. ignore the With, the code works again

See also this:-

with _state
....
dim dt as DataTable =GetData()
.data=dt 'this fails
_state.data=dt 'this succeeds
....
end with

any Ideas?

Guy
Nov 1 '07 #1
7 1517


"guy" wrote:
VB.NET2005 WinXP SP2

I have some code that looks like:-

with _state
...
.data =GetData()
...
end with

where .data is a DataTable

this code has worked fine for 2 weeks

now however although GetData returns 15 rows .data always has rows.count =0

If I change the code to:-

with _state
...
_state.data =GetData()
...
end with

i.e. ignore the With, the code works again

See also this:-

with _state
...
dim dt as DataTable =GetData()
.data=dt 'this fails
_state.data=dt 'this succeeds
...
end with

any Ideas?

Guy

further to this in the same With block

For i as integer=0 to .data.rows.count
dostuff
next

this now fails to enter the loop despite .data.rows.count being = 15
however

For i as integer=0 to _state.data.rows.count
dostuff
next

works correctly!

And yes I have powered the box off and on!

Guy

Nov 1 '07 #2
This is really bizzare!

The loop below does not get entered

with _state
_state.data=getdata
For i as integer=0 to .data.rows.count
dostuff
next
end with

The loop below does get entered

with _state
.data=getdata
_state.data=getdata
For i as integer=0 to .data.rows.count
dostuff
next
end with

and I get a null reference exception itin The 'For' line despite
..data.rows.count =15!

with _state
.data = nothing
_state.data=getdata
For i as integer=0 to .data.rows.count ' null reference exception here
dostuff
next
end with

Guy
Nov 1 '07 #3
Here is the relevant MSIL

for the line '.data = dt'

IL_0072: ldloc.s VB$t_ref$L0
IL_0074: ldloc.1
IL_0075: stfld class [System.Data]System.Data.DataTable
[App_Code.opcms84g]SState::adminTables

and for the line '_state.data =dt'

IL_0072: ldarg.0
IL_0073: ldfld class [App_Code.opcms84g]SState _Default::_state
IL_0078: ldloc.1
IL_0079: stfld class [System.Data]System.Data.DataTable
[App_Code.opcms84g]SState::adminTables

Guy
Nov 1 '07 #4
I ran into a similar problem a long while back with the VB6 Printer object.
'With Printer', followed by '.something=whatever' failed, but
Printer.something worked. I don't recall the details. After much chasing my
tail, I fully qualified all references to Printer.

So... Maybe something is taking precedence over your 'with' statement, as I
am guessing appened to me in VB6. The name of your variable, 'data', is a
name likely to be used in other contexts, and maybe one of those contexts is
defeating the With construct.

To determine this, try:

With _state
.SomeObscureName = whatever
End with

where SomeObscureName is defined in _state and is a name that is unlikely to
be used anywhere else by anybody. If that works, then your result will be
similar to my VB6 result. In my 'with printer' construct, some things worked
and some things didn't. In your case, 'with _state', we know only that .data
does not work. Maybe it does work with a name other than '.data'. If it
does work, it would be interesting to see what the IL is.

"guy" wrote:
VB.NET2005 WinXP SP2

I have some code that looks like:-

with _state
...
.data =GetData()
...
end with

where .data is a DataTable

this code has worked fine for 2 weeks

now however although GetData returns 15 rows .data always has rows.count =0

If I change the code to:-

with _state
...
_state.data =GetData()
...
end with

i.e. ignore the With, the code works again

See also this:-

with _state
...
dim dt as DataTable =GetData()
.data=dt 'this fails
_state.data=dt 'this succeeds
...
end with

any Ideas?

Guy

Nov 1 '07 #5
"guy" <gu*@discussions.microsoft.comschrieb
This is really bizzare!

The loop below does not get entered

with _state
_state.data=getdata
Try to use "go to definition" (shortcut or context menu) in both lines at
the "_state" identifier. Does the cursor jump to the same declaration in
both cases?
Armin

Nov 1 '07 #6
Hi Armin,
hmmm
'go to definition' is greyed out - anywhere in the code, and intellisense
has gone away.
Intellisense went away a week ago, came back when I added a new project, and
then vanished again.

Guy

"Armin Zingler" wrote:
"guy" <gu*@discussions.microsoft.comschrieb
This is really bizzare!

The loop below does not get entered

with _state
_state.data=getdata

Try to use "go to definition" (shortcut or context menu) in both lines at
the "_state" identifier. Does the cursor jump to the same declaration in
both cases?
Armin

Nov 2 '07 #7
"guy" <gu*@discussions.microsoft.comschrieb
Hi Armin,
hmmm
'go to definition' is greyed out - anywhere in the code, and
intellisense has gone away.
Intellisense went away a week ago, came back when I added a new
project, and then vanished again.
That's strange. I currently have no clue how to solve this, sorry... anybody
else?
Armin

Nov 2 '07 #8

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

Similar topics

23
by: Paul Rubin | last post by:
OK, I want to scan a file for lines matching a certain regexp. I'd like to use an assignment expression, like for line in file: if (g := re.match(pat, line)): croggle(g.group(1)) Since...
10
by: Andrew Koenig | last post by:
It has been pointed out to me that various C++ books disagree about the relative precedence of ?: and the assignment operators. In order to satisfy myself about the matter once and for all, I...
5
by: CoolPint | last post by:
It seems to me that I cannot assign objects of a class which has a constant data member since the data member cannot be changed once the constructor calls are completed. Is this the way it is meant...
16
by: Edward Diener | last post by:
Is there a way to override the default processing of the assignment operator for one's own __value types ? I realize I can program my own Assign method, and provide that for end-users of my class,...
9
by: Rick N. Backer | last post by:
I have an abstract base class that has char* members. Is an assignment operator necessary for this abstract base class? Why or why not? Thanks in advance. Ken Wilson Amer. Dlx. Tele,...
1
by: Jon Slaughter | last post by:
I have a chain of classes(i.e., a series of classes each containing an array of the next class). Each class has array like access. struct Myclass1 { vector(Myclass2) _Myclass2; Myclass2&...
166
by: Graham | last post by:
This has to do with class variables and instances variables. Given the following: <code> class _class: var = 0 #rest of the class
6
by: Neil Zanella | last post by:
Hello, I would like to know whether the following C fragment is legal in standard C and behaves as intended under conforming implementations... union foo { char c; double d; };
35
by: nagy | last post by:
I do the following. First create lists x,y,z. Then add an element to x using the augumented assignment operator. This causes all the other lists to be changed also. But if I use the assignment...
20
by: TimeHorse | last post by:
I would like to gauge interest in the following proposal: Problem: Assignment statements cannot be used as expressions. Performing a list of mutually exclusive checks that require data...
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
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...
1
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
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.