473,324 Members | 2,193 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,324 software developers and data experts.

Assigning Nullables to each other

In my property declaration, shown below, is it
correct to assign _DeptID = Value like I would have if it was just a
plain ole Integer, or is this like setting two objects equal to each
other where the end result is that the one on the left now points to
the same memory address as the one on the right? Should I instead be
assigning _DeptID.Value = Value.Value or _DeptID.Value =
CInt(Value.Value)?

Public Property DeptID() As Nullable(Of Integer)
Get
Return _DeptID
End Get
Set(ByVal Value As Nullable(Of Integer))
If Not Value.Equals(_DeptID) Then
_DeptID = Value
_HasChanged = True
End If
End Set
End Property ' DeptID

Jun 16 '06 #1
6 899
In my property declaration, shown below, is it
correct to assign _DeptID = Value like I would have if it was just a
plain ole Integer, or is this like setting two objects equal to each
other where the end result is that the one on the left now points to
the same memory address as the one on the right?

Nullable(Of T) is a structure, so you'll store a copy of the value.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jun 16 '06 #2
Thanks Mattias...sounds like it's cool the way I'm doing it then.
Another question, if you don't mind...

If I wanted to create a function, called let's say
GetNullableIntFromIntField, which took as its input an integer field
coming in from a DB
(e.g. rdr("DeptID")) and gave back either Nothing or the integer value,

what would the Function declaration look like?
Function GetNullableIntFromIntField(ByVal oSomething As ???) As ???
If IsDBNull(oSomething) Then
Return Nothing
Else
Return CInt(oSomething)
End If
End Function

Jun 16 '06 #3
>what would the Function declaration look like?


Function GetNullableIntFromIntField(ByVal oSomething As ???) As ???

Function GetNullableIntFromIntField(ByVal oSomething As Object) As
Nullable(Of Integer)

or if you want to generalize it a bit

Function GetNullableFromField(Of T As {Structure})(ByVal oSomething As
Object) As Nullable(Of T)
If IsDBNull(oSomething) Then
Return Nothing
Else
Return CType(oSomething, T)
End If
End Function
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jun 16 '06 #4

Mattias Sjögren wrote:
what would the Function declaration look like?
Function GetNullableIntFromIntField(ByVal oSomething As ???) As ???

Function GetNullableIntFromIntField(ByVal oSomething As Object) As
Nullable(Of Integer)


This gives me an error message, in the editor environment stating
"Nullable is a type and cannot be used as an expression"
or if you want to generalize it a bit

Function GetNullableFromField(Of T As {Structure})(ByVal oSomething As
Object) As Nullable(Of T)
If IsDBNull(oSomething) Then
Return Nothing
Else
Return CType(oSomething, T)
End If
End Function


I like the idea of a general function, since I have to deal with Dates
and Booleans as well. However, I get error messages, when trying to
Build, related to this one...

Error 9 'Object' is a class type and cannot be used as an expression.

In the editor environment it states, when I hover over the function
name, "Function without an 'As' clause; return type of object assumed."

Jun 16 '06 #5
>> Function GetNullableIntFromIntField(ByVal oSomething As Object) As
Nullable(Of Integer)


This gives me an error message, in the editor environment stating
"Nullable is a type and cannot be used as an expression"


Put it all on the same line (or use the _ line continuation
character). It's just broken up by my newsreader. It should be (if we
shorten the names a bit)

Function X(ByVal y As Object) As Nullable(Of Integer)
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jun 17 '06 #6
Yup...that did it...was obviously up way too late copying and pasting
that code in...not paying attention to an obvious thing like that!
Thanks...

Jun 18 '06 #7

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

Similar topics

10
by: Matthew Sims | last post by:
Python Newbie here. This is my first time learning object-oriented programming and trying to break out of the usual Korn/Perl/PHP style of programming. Having some difficulty understand some items....
10
by: rxl124 | last post by:
I have files that I only need one field that I need to grep it out and I am trying to assign that to another file. (It happens that one field that I am looking for has some other character that...
7
by: Sandman | last post by:
I have a script that generates a hierarchical menu, but I am having problems assigning styles to each manu items different possible states. The possible states a menu item can be in is (and all of...
14
by: Eric Bantock | last post by:
Very basic question I'm afraid. Once an array has been declared, is there a less tedious way of assigning values to its members than the following: myarray=8; myarray=3; myarray=4; myarray=0;...
8
by: Viken Karaguesian | last post by:
Hello all, I'll start with this question: Can I assign an ID *and* a CLASS to a DIV? I am under the impression that you can. I'm having a problem that I can't seem to figure out. Some...
7
by: Joe Bloggs | last post by:
Hi, Can someone please kindly show me how to determine if a type (read value type) is Nullable. MSDN has this KB: How to: Identify a Nullable Type (C# Programming Guide)...
31
by: leonm54 | last post by:
I remember that this is a bad practice, but can not find a definitive resource that states it is bad and why. Can anyone help?
8
by: =?Utf-8?B?VHJlY2l1cw==?= | last post by:
Hello, Newsgroupians: I have a large class with a lot of member variables. I also have a function in the class that I would like to change ALL Of the member variables. I am trying to assign...
1
by: The Pythonista | last post by:
I've been wondering for a while about whether assigning to __class__ is bad form or not. Specifically, I mean doing so when some other method of implementing the functionality you're after is...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.