Is Nothing problem

S

shapper

Hello,

I have a generic list as follows:
Dim rows As New Generic.List(Of row)

Now I have a row:
Dim myRow As row

I tried to check, further in my code, if the row is nothing:
If myRow Is Nothing Then
....
End If

I get an error:
"Is" requires operand that have reference types but this operand has
the value of Rows.Row"

Any idea what I am doing wrong?

Anyway, this is my row definition and its dependencies:

' Row
Public Structure Row

' -- [Properties] ----

' Cells
Private _Cells As Generic.List(Of Cell)
Public Property Cells() As Generic.List(Of Cell)
Get
Return _Cells
End Get
Set(ByVal Cells As Generic.List(Of Cell))
_Cells = Cells
End Set
End Property ' Cells

' Name
Private _Name As String
Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal Name As String)
_Name = Name
End Set
End Property ' Name

End Structure ' Row

' Cell
Public Structure Cell

' -- [Properties] ----

' Content
Private _Content As Object
Public Property Content() As Object
Get
Return _Content
End Get
Set(ByVal Content As Object)
_Content = Content
End Set
End Property ' Content

' Culture
Private _Culture As CultureInfo
Public Property Culture() As CultureInfo
Get
Return _Culture
End Get
Set(ByVal Culture As CultureInfo)
_Culture = Culture
End Set
End Property ' Culture

End Structure ' Cell

Thanks,
Miguel
 
G

Guest

Actually, "= Nothing" won't work unless you have overloaded the '=' operator
in your structure.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: C#/VB to Python converter
 
S

shapper

If myRow = Nothing Then

I have tried that before and it didn't work.

Basically my code is:

Dim myRow As Rows.Row = allRows.Rows.Find(AddressOf
FindRowByName.Search)

If rBox = Nothing Then ...

I get the error:
Operator '=' is not defined for Rows.Row

Any idea?

Thanks,
Miguel
 
G

Guest

Even though VB allows the use of "Nothing" with structure types (such as
Int32 for example), it tends to be confusing (and requires overloading the
Equals operator). What you should do instead is have a read only property on
your structure, such as "IsInitialized", which returns true if the instance
is explicitly initialized or populated.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: C#/VB to Python converter
 
M

Mike Hofer

I have tried that before and it didn't work.

Basically my code is:

Dim myRow As Rows.Row = allRows.Rows.Find(AddressOf
FindRowByName.Search)

If rBox = Nothing Then ...

I get the error:
Operator '=' is not defined for Rows.Row

Any idea?

Thanks,
Miguel

Here's a question for you: Does your Search method ever return Nothing?
 
S

shapper

Here's a question for you: Does your Search method ever return Nothing?

My Search method returns true or false. It is a Predicate to be used
under Generic.List Find. So basically I need to check if the Find
command found anything.

Anyway, If it helps here is my Predicate class:

' FindRowByName
Public Class FindRowByName

' -- [Properties] -------------------------------------------

' RowName
Private _RowName As String
Public Property RowName() As String
Get
Return _RowName
End Get
Set(ByVal value As String)
_RowName = value
End Set
End Property ' RowName


' -- [Methods] -------------------------------------------

' New
Public Sub New(ByVal rowName As String)

' Define class properties
Me.RowName = rowName

End Sub ' New

' Search
Public Function Search(ByVal row As BoxRows.Row) As Boolean

' Return comparison value
Return String.Equals(row.Name, Me.RowName)

End Function ' Search

End Class ' FindRowByName

Thanks,
Miguel
 
S

shapper

Even though VB allows the use of "Nothing" with structure types (such as
Int32 for example), it tends to be confusing (and requires overloading the
Equals operator). What you should do instead is have a read only property on
your structure, such as "IsInitialized", which returns true if the instance
is explicitly initialized or populated.
--
David Antonwww.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: C#/VB to Python converter

shapper said:
I have a generic list as follows:
Dim rows As New Generic.List(Of row)
Now I have a row:
Dim myRow As row
I tried to check, further in my code, if the row is nothing:
If myRow Is Nothing Then
....
End If
I get an error:
"Is" requires operand that have reference types but this operand has
the value of Rows.Row"
Any idea what I am doing wrong?
Anyway, this is my row definition and its dependencies:
' Row
Public Structure Row
' -- [Properties] ----
' Cells
Private _Cells As Generic.List(Of Cell)
Public Property Cells() As Generic.List(Of Cell)
Get
Return _Cells
End Get
Set(ByVal Cells As Generic.List(Of Cell))
_Cells = Cells
End Set
End Property ' Cells
' Name
Private _Name As String
Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal Name As String)
_Name = Name
End Set
End Property ' Name
End Structure ' Row
' Cell
Public Structure Cell
' -- [Properties] ----
' Content
Private _Content As Object
Public Property Content() As Object
Get
Return _Content
End Get
Set(ByVal Content As Object)
_Content = Content
End Set
End Property ' Content
' Culture
Private _Culture As CultureInfo
Public Property Culture() As CultureInfo
Get
Return _Culture
End Get
Set(ByVal Culture As CultureInfo)
_Culture = Culture
End Set
End Property ' Culture
End Structure ' Cell
Thanks,
Miguel

David,

I am a little bit lost.
You mean that I should create a New Method on my structure which sets
a property IsInitialized to true, being IsInitialized default value
set to false?

And how can that help me?

Remember I am using List.Find to get a row.

Thanks,
Miguel
 
M

Mike Hofer

Here's a question for you: Does your Search method ever return Nothing?

My Search method returns true or false. It is a Predicate to be used
under Generic.List Find. So basically I need to check if the Find
command found anything.

Anyway, If it helps here is my Predicate class:

' FindRowByName
Public Class FindRowByName

' -- [Properties] -------------------------------------------

' RowName
Private _RowName As String
Public Property RowName() As String
Get
Return _RowName
End Get
Set(ByVal value As String)
_RowName = value
End Set
End Property ' RowName

' -- [Methods] -------------------------------------------

' New
Public Sub New(ByVal rowName As String)

' Define class properties
Me.RowName = rowName

End Sub ' New

' Search
Public Function Search(ByVal row As BoxRows.Row) As Boolean

' Return comparison value
Return String.Equals(row.Name, Me.RowName)

End Function ' Search

End Class ' FindRowByName

Thanks,
Miguel- Hide quoted text -

- Show quoted text -

Okay, I gotcha now. So your FindRowByName method, what is its return
type? And what can it return? Does it ever return Nothing?
 
S

shapper

My Search method returns true or false. It is a Predicate to be used
under Generic.List Find. So basically I need to check if the Find
command found anything.
Anyway, If it helps here is my Predicate class:
' FindRowByName
Public Class FindRowByName
' -- [Properties] -------------------------------------------
' RowName
Private _RowName As String
Public Property RowName() As String
Get
Return _RowName
End Get
Set(ByVal value As String)
_RowName = value
End Set
End Property ' RowName
' -- [Methods] -------------------------------------------
' New
Public Sub New(ByVal rowName As String)
' Define class properties
Me.RowName = rowName
End Sub ' New
' Search
Public Function Search(ByVal row As BoxRows.Row) As Boolean
' Return comparison value
Return String.Equals(row.Name, Me.RowName)
End Function ' Search
End Class ' FindRowByName
Thanks,
Miguel- Hide quoted text -
- Show quoted text -

Okay, I gotcha now. So your FindRowByName method, what is its return
type? And what can it return? Does it ever return Nothing?

Mark,

See 2 threads before. FindRowByName is a class which has a method
Search which returns true or false.

Thanks,
Miguel
 
M

Mike Hofer

If myRow Is Nothing Then
If myRow = Nothing Then
I have tried that before and it didn't work.
Basically my code is:
Dim myRow As Rows.Row = allRows.Rows.Find(AddressOf
FindRowByName.Search)
If rBox = Nothing Then ...
I get the error:
Operator '=' is not defined for Rows.Row
Any idea?
Thanks,
Miguel
Here's a question for you: Does your Search method ever return Nothing?
My Search method returns true or false. It is a Predicate to be used
under Generic.List Find. So basically I need to check if the Find
command found anything.
Anyway, If it helps here is my Predicate class:
' FindRowByName
Public Class FindRowByName
' -- [Properties] -------------------------------------------
' RowName
Private _RowName As String
Public Property RowName() As String
Get
Return _RowName
End Get
Set(ByVal value As String)
_RowName = value
End Set
End Property ' RowName
' -- [Methods] -------------------------------------------
' New
Public Sub New(ByVal rowName As String)
' Define class properties
Me.RowName = rowName
End Sub ' New
' Search
Public Function Search(ByVal row As BoxRows.Row) As Boolean
' Return comparison value
Return String.Equals(row.Name, Me.RowName)
End Function ' Search
End Class ' FindRowByName
Thanks,
Miguel- Hide quoted text -
- Show quoted text -
Okay, I gotcha now. So your FindRowByName method, what is its return
type? And what can it return? Does it ever return Nothing?

Mark,

See 2 threads before. FindRowByName is a class which has a method
Search which returns true or false.

Thanks,
Miguel- Hide quoted text -

- Show quoted text -

Gah! I'm being especially dense today; sorry about that. It's been a
tough one.

What I'm getting at is whether or not the FIND method is capable of
returning a Nothing value. This is the line I'm interested in:

Dim myRow As Rows.Row = allRows.Rows.Find(AddressOf
FindRowByName.Search)

It returns a Rows.Row object, which, theoretically is a value (since
structures are value types). But what does it return if there is no
matching value?

I'm honestly not trying to be condescending. I'm just trying to
understanding the code in question. There may be a better way to test
for a match failure.

Again, I'm sorry for being so darned thickheaded today.

Mike
 
S

shapper

If myRow Is Nothing Then
If myRow = Nothing Then
I have tried that before and it didn't work.
Basically my code is:
Dim myRow As Rows.Row = allRows.Rows.Find(AddressOf
FindRowByName.Search)
If rBox = Nothing Then ...
I get the error:
Operator '=' is not defined for Rows.Row
Any idea?
Thanks,
Miguel
Here's a question for you: Does your Search method ever return Nothing?
My Search method returns true or false. It is a Predicate to be used
under Generic.List Find. So basically I need to check if the Find
command found anything.
Anyway, If it helps here is my Predicate class:
' FindRowByName
Public Class FindRowByName
' -- [Properties] -------------------------------------------
' RowName
Private _RowName As String
Public Property RowName() As String
Get
Return _RowName
End Get
Set(ByVal value As String)
_RowName = value
End Set
End Property ' RowName
' -- [Methods] -------------------------------------------
' New
Public Sub New(ByVal rowName As String)
' Define class properties
Me.RowName = rowName
End Sub ' New
' Search
Public Function Search(ByVal row As BoxRows.Row) As Boolean
' Return comparison value
Return String.Equals(row.Name, Me.RowName)
End Function ' Search
End Class ' FindRowByName
Thanks,
Miguel- Hide quoted text -
- Show quoted text -
Okay, I gotcha now. So your FindRowByName method, what is its return
type? And what can it return? Does it ever return Nothing?

See 2 threads before. FindRowByName is a class which has a method
Search which returns true or false.
Thanks,
Miguel- Hide quoted text -
- Show quoted text -

Gah! I'm being especially dense today; sorry about that. It's been a
tough one.

What I'm getting at is whether or not the FIND method is capable of
returning a Nothing value. This is the line I'm interested in:

Dim myRow As Rows.Row = allRows.Rows.Find(AddressOf
FindRowByName.Search)

It returns a Rows.Row object, which, theoretically is a value (since
structures are value types). But what does it return if there is no
matching value?

I'm honestly not trying to be condescending. I'm just trying to
understanding the code in question. There may be a better way to test
for a match failure.

Again, I'm sorry for being so darned thickheaded today.

Mike

Hi Mike,

No problem ... I am not so good in explaining my problem to.

Anyway, I will try to explain the best I can.

In line:
Dim myRow As Rows.Row = allRows.Rows.Find(AddressOf
FindRowByName.Search)

FindRowByName.Seach returns True when it is a match and False when it
is not.

Rows is a generic list of Row. I am using the List.Find command:
http://msdn2.microsoft.com/en-us/library/x0b5b5bc.aspx

As I read in that text:

"Parameters

Match
The Predicate delegate that defines the conditions of the element
to search for.

Return Value
The first element that matches the conditions defined by the
specified predicate, if found; otherwise, the default value for type
T."

So when it is not a match it returns the default value for type T, I
believe in my case, the default value of Row.

Now I wonder what is the default value of Row and how can I check it.

My Row Structure is:

' Row
Public Structure Row

' -- [Properties] ----

' Cells
Private _Cells As Generic.List(Of Cell)
Public Property Cells() As Generic.List(Of Cell)
Get
Return _Cells
End Get
Set(ByVal Cells As Generic.List(Of Cell))
_Cells = Cells
End Set
End Property ' Cells

' Name
Private _Name As String
Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal Name As String)
_Name = Name
End Set
End Property ' Name

End Structure ' Row

What do you think I should do?

Thank You for the Help,
Miguel
 
M

Mike Hofer

If myRow Is Nothing Then
If myRow = Nothing Then
I have tried that before and it didn't work.
Basically my code is:
Dim myRow As Rows.Row = allRows.Rows.Find(AddressOf
FindRowByName.Search)
If rBox = Nothing Then ...
I get the error:
Operator '=' is not defined for Rows.Row
Any idea?
Thanks,
Miguel
Here's a question for you: Does your Search method ever return Nothing?
My Search method returns true or false. It is a Predicate to be used
under Generic.List Find. So basically I need to check if the Find
command found anything.
Anyway, If it helps here is my Predicate class:
' FindRowByName
Public Class FindRowByName
' -- [Properties] -------------------------------------------
' RowName
Private _RowName As String
Public Property RowName() As String
Get
Return _RowName
End Get
Set(ByVal value As String)
_RowName = value
End Set
End Property ' RowName
' -- [Methods] -------------------------------------------
' New
Public Sub New(ByVal rowName As String)
' Define class properties
Me.RowName = rowName
End Sub ' New
' Search
Public Function Search(ByVal row As BoxRows.Row) As Boolean
' Return comparison value
Return String.Equals(row.Name, Me.RowName)
End Function ' Search
End Class ' FindRowByName
Thanks,
Miguel- Hide quoted text -
- Show quoted text -
Okay, I gotcha now. So your FindRowByName method, what is its return
type? And what can it return? Does it ever return Nothing?
Mark,
See 2 threads before. FindRowByName is a class which has a method
Search which returns true or false.
Thanks,
Miguel- Hide quoted text -
- Show quoted text -
Gah! I'm being especially dense today; sorry about that. It's been a
tough one.
What I'm getting at is whether or not the FIND method is capable of
returning a Nothing value. This is the line I'm interested in:
Dim myRow As Rows.Row = allRows.Rows.Find(AddressOf
FindRowByName.Search)
It returns a Rows.Row object, which, theoretically is a value (since
structures are value types). But what does it return if there is no
matching value?
I'm honestly not trying to be condescending. I'm just trying to
understanding the code in question. There may be a better way to test
for a match failure.
Again, I'm sorry for being so darned thickheaded today.

Hi Mike,

No problem ... I am not so good in explaining my problem to.

Anyway, I will try to explain the best I can.

In line:
Dim myRow As Rows.Row = allRows.Rows.Find(AddressOf
FindRowByName.Search)

FindRowByName.Seach returns True when it is a match and False when it
is not.

Rows is a generic list of Row. I am using the List.Find command:http://msdn2.microsoft.com/en-us/library/x0b5b5bc.aspx

As I read in that text:

"Parameters

Match
The Predicate delegate that defines the conditions of the element
to search for.

Return Value
The first element that matches the conditions defined by the
specified predicate, if found; otherwise, the default value for type
T."

So when it is not a match it returns the default value for type T, I
believe in my case, the default value of Row.

Now I wonder what is the default value of Row and how can I check it.

My Row Structure is:

' Row
Public Structure Row

' -- [Properties] ----

' Cells
Private _Cells As Generic.List(Of Cell)
Public Property Cells() As Generic.List(Of Cell)
Get
Return _Cells
End Get
Set(ByVal Cells As Generic.List(Of Cell))
_Cells = Cells
End Set
End Property ' Cells

' Name
Private _Name As String
Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal Name As String)
_Name = Name
End Set
End Property ' Name

End Structure ' Row

What do you think I should do?

Thank You for the Help,
Miguel- Hide quoted text -

- Show quoted text -

If you're getting the default value of a Rows.Row, then what you're
getting is the equivalent of this:

Return New Rows.Row()

It's a new structure, with the default constructor called. With the
Rows.Row structure written the way it is, it's difficult to test it
for proper initialization.

Have you considered converting it to a full-fledged class? Doing so
doesn't really introduce all that much overhead, and then you could
easily test it for nothingness. Or is there a compelling reason not to
do so? (If it *was* a class, it's default value would be Nothing.)
 
S

shapper

If myRow Is Nothing Then
If myRow = Nothing Then
I have tried that before and it didn't work.
Basically my code is:
Dim myRow As Rows.Row = allRows.Rows.Find(AddressOf
FindRowByName.Search)
If rBox = Nothing Then ...
I get the error:
Operator '=' is not defined for Rows.Row
Any idea?
Thanks,
Miguel
Here's a question for you: Does your Search method ever return Nothing?
My Search method returns true or false. It is a Predicate to be used
under Generic.List Find. So basically I need to check if the Find
command found anything.
Anyway, If it helps here is my Predicate class:
' FindRowByName
Public Class FindRowByName
' -- [Properties] -------------------------------------------
' RowName
Private _RowName As String
Public Property RowName() As String
Get
Return _RowName
End Get
Set(ByVal value As String)
_RowName = value
End Set
End Property ' RowName
' -- [Methods] -------------------------------------------
' New
Public Sub New(ByVal rowName As String)
' Define class properties
Me.RowName = rowName
End Sub ' New
' Search
Public Function Search(ByVal row As BoxRows.Row) As Boolean
' Return comparison value
Return String.Equals(row.Name, Me.RowName)
End Function ' Search
End Class ' FindRowByName
Thanks,
Miguel- Hide quoted text -
- Show quoted text -
Okay, I gotcha now. So your FindRowByName method, what is its return
type? And what can it return? Does it ever return Nothing?
Mark,
See 2 threads before. FindRowByName is a class which has a method
Search which returns true or false.
Thanks,
Miguel- Hide quoted text -
- Show quoted text -
Gah! I'm being especially dense today; sorry about that. It's been a
tough one.
What I'm getting at is whether or not the FIND method is capable of
returning a Nothing value. This is the line I'm interested in:
Dim myRow As Rows.Row = allRows.Rows.Find(AddressOf
FindRowByName.Search)
It returns a Rows.Row object, which, theoretically is a value (since
structures are value types). But what does it return if there is no
matching value?
I'm honestly not trying to be condescending. I'm just trying to
understanding the code in question. There may be a better way to test
for a match failure.
Again, I'm sorry for being so darned thickheaded today.
Mike
No problem ... I am not so good in explaining my problem to.
Anyway, I will try to explain the best I can.
In line:
Dim myRow As Rows.Row = allRows.Rows.Find(AddressOf
FindRowByName.Search)
FindRowByName.Seach returns True when it is a match and False when it
is not.
Rows is a generic list of Row. I am using the List.Find command:http://msdn2.microsoft.com/en-us/library/x0b5b5bc.aspx
As I read in that text:

Match
The Predicate delegate that defines the conditions of the element
to search for.
Return Value
The first element that matches the conditions defined by the
specified predicate, if found; otherwise, the default value for type
T."
So when it is not a match it returns the default value for type T, I
believe in my case, the default value of Row.
Now I wonder what is the default value of Row and how can I check it.
My Row Structure is:
' Row
Public Structure Row
' -- [Properties] ----
' Cells
Private _Cells As Generic.List(Of Cell)
Public Property Cells() As Generic.List(Of Cell)
Get
Return _Cells
End Get
Set(ByVal Cells As Generic.List(Of Cell))
_Cells = Cells
End Set
End Property ' Cells
' Name
Private _Name As String
Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal Name As String)
_Name = Name
End Set
End Property ' Name
End Structure ' Row
What do you think I should do?
Thank You for the Help,
Miguel- Hide quoted text -
- Show quoted text -

If you're getting the default value of a Rows.Row, then what you're
getting is the equivalent of this:

Return New Rows.Row()

It's a new structure, with the default constructor called. With the
Rows.Row structure written the way it is, it's difficult to test it
for proper initialization.

Have you considered converting it to a full-fledged class? Doing so
doesn't really introduce all that much overhead, and then you could
easily test it for nothingness. Or is there a compelling reason not to
do so? (If it *was* a class, it's default value would be Nothing.)

I see. Making Row and Cell classes instead of structures.
Then I would have:

Rows as a Generic.List(Of Row)
and
Row as a Generic-List(Of Cell)

This is a possible way.
Rows is a Serializable class because I am using Binary Serialization
to save Rows in a SQL VarBinary table field.

I just have one question:

I believe I just need to make both Row and Cell Serializable as I do
to Rows:

<Serializable()> _
Public Class Row
...

Then when I serialize Rows I will also serialize the dependent
classes, i.e., Row and Cell, right?

Just to confirm.

I think turning it to classes is the way to go. Thanks for your tip.

Thanks,
Miguel
 
M

Mike Hofer

If myRow Is Nothing Then
If myRow = Nothing Then
I have tried that before and it didn't work.
Basically my code is:
Dim myRow As Rows.Row = allRows.Rows.Find(AddressOf
FindRowByName.Search)
If rBox = Nothing Then ...
I get the error:
Operator '=' is not defined for Rows.Row
Any idea?
Thanks,
Miguel
Here's a question for you: Does your Search method ever return Nothing?
My Search method returns true or false. It is a Predicate to be used
under Generic.List Find. So basically I need to check if the Find
command found anything.
Anyway, If it helps here is my Predicate class:
' FindRowByName
Public Class FindRowByName
' -- [Properties] -------------------------------------------
' RowName
Private _RowName As String
Public Property RowName() As String
Get
Return _RowName
End Get
Set(ByVal value As String)
_RowName = value
End Set
End Property ' RowName
' -- [Methods] -------------------------------------------
' New
Public Sub New(ByVal rowName As String)
' Define class properties
Me.RowName = rowName
End Sub ' New
' Search
Public Function Search(ByVal row As BoxRows.Row) As Boolean
' Return comparison value
Return String.Equals(row.Name, Me.RowName)
End Function ' Search
End Class ' FindRowByName
Thanks,
Miguel- Hide quoted text -
- Show quoted text -
Okay, I gotcha now. So your FindRowByName method, what is its return
type? And what can it return? Does it ever return Nothing?
Mark,
See 2 threads before. FindRowByName is a class which has a method
Search which returns true or false.
Thanks,
Miguel- Hide quoted text -
- Show quoted text -
Gah! I'm being especially dense today; sorry about that. It's been a
tough one.
What I'm getting at is whether or not the FIND method is capable of
returning a Nothing value. This is the line I'm interested in:
Dim myRow As Rows.Row = allRows.Rows.Find(AddressOf
FindRowByName.Search)
It returns a Rows.Row object, which, theoretically is a value (since
structures are value types). But what does it return if there is no
matching value?
I'm honestly not trying to be condescending. I'm just trying to
understanding the code in question. There may be a better way to test
for a match failure.
Again, I'm sorry for being so darned thickheaded today.
Mike
Hi Mike,
No problem ... I am not so good in explaining my problem to.
Anyway, I will try to explain the best I can.
In line:
Dim myRow As Rows.Row = allRows.Rows.Find(AddressOf
FindRowByName.Search)
FindRowByName.Seach returns True when it is a match and False when it
is not.
Rows is a generic list of Row. I am using the List.Find command:http://msdn2.microsoft.com/en-us/library/x0b5b5bc.aspx
As I read in that text:
"Parameters
Match
The Predicate delegate that defines the conditions of the element
to search for.
Return Value
The first element that matches the conditions defined by the
specified predicate, if found; otherwise, the default value for type
T."
So when it is not a match it returns the default value for type T, I
believe in my case, the default value of Row.
Now I wonder what is the default value of Row and how can I check it.
My Row Structure is:
' Row
Public Structure Row
' -- [Properties] ----
' Cells
Private _Cells As Generic.List(Of Cell)
Public Property Cells() As Generic.List(Of Cell)
Get
Return _Cells
End Get
Set(ByVal Cells As Generic.List(Of Cell))
_Cells = Cells
End Set
End Property ' Cells
' Name
Private _Name As String
Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal Name As String)
_Name = Name
End Set
End Property ' Name
End Structure ' Row
What do you think I should do?
Thank You for the Help,
Miguel- Hide quoted text -
- Show quoted text -
If you're getting the default value of a Rows.Row, then what you're
getting is the equivalent of this:
Return New Rows.Row()
It's a new structure, with the default constructor called. With the
Rows.Row structure written the way it is, it's difficult to test it
for proper initialization.
Have you considered converting it to a full-fledged class? Doing so
doesn't really introduce all that much overhead, and then you could
easily test it for nothingness. Or is there a compelling reason not to
do so? (If it *was* a class, it's default value would be Nothing.)

I see. Making Row and Cell classes instead of structures.
Then I would have:

Rows as a Generic.List(Of Row)
and
Row as a Generic-List(Of Cell)

This is a possible way.
Rows is a Serializable class because I am using Binary Serialization
to save Rows in a SQL VarBinary table field.

I just have one question:

I believe I just need to make both Row and Cell Serializable as I do
to Rows:

<Serializable()> _
Public Class Row
...

Then when I serialize Rows I will also serialize the dependent
classes, i.e., Row and Cell, right?

Just to confirm.

I think turning it to classes is the way to go. Thanks for your tip.

Thanks,
Miguel- Hide quoted text -

- Show quoted text -

As far as I can recall, unless you're doing something spectacular (or
fairly obtuse), you shouldn't have to implement any special code to
serialize the objects once you mark them with the <Serializable()>
attribute. I'm assuming, of course, that you're just using value types
in the classes, or object types that are also marked as
<Serializable()>.

But it's always worth confirming that in the documentation.

The special case is, of course, nested trees of objects or circular
references, which doesn't appear to apply here.

Good luck, and I hope this all turns out well for you. Keep us posted,
and let us know how it turns out!

Mike
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

shapper said:
Hello,

I have a generic list as follows:
Dim rows As New Generic.List(Of row)

Now I have a row:
Dim myRow As row

I tried to check, further in my code, if the row is nothing:
If myRow Is Nothing Then
...
End If

I get an error:
"Is" requires operand that have reference types but this operand has
the value of Rows.Row"

Any idea what I am doing wrong?

A structure is a value type, and can not be Nothing. Nothing is the
keyword VB uses for null.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top