request syntax for using Option Strict

  • Thread starter Thread starter Rich
  • Start date Start date
R

Rich

Hello,

If I leave Option Strict Off I can use the following
syntax to read data from a Lotus Notes application (a
NotesViewEntry object represents a row of data from a
Lotus Notes View - like a record in a sql Server view)
....
Dim entry As Domino.NotesViewEntry
Dim obj As Object
str1 = entry.ColumnValues(0)
For Each obj In entry.ColumnValues
str1 = obj
....

But if I turn Option Strict on then I get a "Late Binding
not allowed" error for

str1 = entry.ColumnValues(0)

and "Expression is of type System Object which is not a
collection type" for

For Each obj In entry.ColumnValues
....

I also tried

Dim obj() As Object = entry.ColumValues

and got the error message that "Option Strict doesn't
allow implicit conversions from System.Object to a 1
dimensional array of System.Object"

But it did allow
Dim obj As Object = entry.ColumnValues

Could anyone suggest conversion syntax or how I could
extract data from obj with Option Strict on? As long as I
am using .Net, I am trying to get into the habit of using
it correctly.

TIA,
Rich
 
Rich said:
Hello,

If I leave Option Strict Off I can use the following
syntax to read data from a Lotus Notes application (a
NotesViewEntry object represents a row of data from a
Lotus Notes View - like a record in a sql Server view)
...
Dim entry As Domino.NotesViewEntry
Dim obj As Object
str1 = entry.ColumnValues(0)
For Each obj In entry.ColumnValues
str1 = obj
...

But if I turn Option Strict on then I get a "Late Binding
not allowed" error for

str1 = entry.ColumnValues(0)

I assume you declared str1 As String as in your last post?

Are you sure ColumnValues(0) always returns a string? If it does, use

str1 = entry.ColumnValues(0).ToString

and "Expression is of type System Object which is not a
collection type" for

For Each obj In entry.ColumnValues
...


What is the type of the ColumnValues property? I guess it's Object. What
type is really returned at runtime? To find it out, assign it to a variable
declared as Object and have a look at the Debug/Locals window. Then change
your code and cast to that type:

For Each obj In directcast(entry.ColumnValues, <EnterTypeHere>)

What type of items are contained in ColumnValues? You can declare variable
'obj' as this type.

I also tried

Dim obj() As Object = entry.ColumValues

and got the error message that "Option Strict doesn't
allow implicit conversions from System.Object to a 1
dimensional array of System.Object"

But it did allow
Dim obj As Object = entry.ColumnValues

Could anyone suggest conversion syntax or how I could
extract data from obj with Option Strict on? As long as I
am using .Net, I am trying to get into the habit of using
it correctly.


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
Thanks all for your replies, but I have tried variations
of your suggestions without success. With Option Strict
On I keep getting the message that "Late Binding not
allowed"

str = Cstr(entry.ColumnValues(0)) --- won't work with
Option Strict on - says entry or entry.ColumnValues is a
System.Object. If it works with Option Strict Off then I
am sure it will work with Option Strict On - just "what is
the correct syntax?" I would really like to reap the
benefit of early binding. Note: sometime a value from
entry.ColumnValues(i) could be an array (a variant) from
which in VB6 I had to say str1 = Itm(0)
(checked if IsArray(Itm) then str1 = Itm(0)). This also
works with Option Strict off. So the question is "what
does VB.Net think a NotesViewEntry object is?" for early
binding. It seems to figure out what a NotesViewEntry
object is with Late binding. Early binding calls it a
System.Object. How can I access the contents of this
object?

Thanks for your replies,
Rich
 
try str = DirectCast(entry.ColumnValues(0), String)
or str = CType(entry.ColumnValues(0), String)

also, if you're saying that .net is recognizing entry.ColumnValues(0) as
a 'Object' type, you could do what Armin suggested..that should work..

hope this helps..
 
Thanks but already tried that to no avail. I think my
real question would be if the VB.Net compiler can perform
late binding on an object does that guarantee that early
binding can be performed - if the data type is known?

It turns out the the NotesViewEntry object is actually an
array of variant (or objects in .Net language) per the
help files in Lotus Notes Designer help. Tommorrow I will
try CType(entry.ColumnValues, ArrayList)

or something that is an array of objects. Right now, the
VB.Net compiler regards the NotesViewEntry object as a
system.Object type. But eventually it seems to figure out
what it is because with Option Strict Off my VB6 codes
runs in VB.Net. I just believe that I would see a
signifcant gain in performance if I could do this with
early binding.

So what kind of VB.Net object (datatype) is an array of
objects?

Thanks,
Rich
 
I don't think you can use the OPTION STRICT ON in this case. I was
looking at the object model for the Domino OBJECT (spefically what the
ColumnValues returns). It returns a variant array.

If the OPTION STRICT requires explicit conversions, you have to test
the type of each ColumnValue(i) to figure out what it's type is and
convert it to the destination type.

Maybe? Then again, I may not know what I'm talking about since I've
only been programming in vb.net for 2.75 days now.

William
 
Rich said:
Thanks but already tried that to no avail. I think my
real question would be if the VB.Net compiler can perform
late binding on an object does that guarantee that early
binding can be performed - if the data type is known?

It turns out the the NotesViewEntry object is actually an
array of variant (or objects in .Net language) per the
help files in Lotus Notes Designer help. Tommorrow I will
try CType(entry.ColumnValues, ArrayList)
or something that is an array of objects. Right now, the
VB.Net compiler regards the NotesViewEntry object as a
system.Object type. But eventually it seems to figure out
what it is because with Option Strict Off my VB6 codes
runs in VB.Net. I just believe that I would see a
signifcant gain in performance if I could do this with
early binding.

So what kind of VB.Net object (datatype) is an array of
objects?


Why not have a look at the object and it's type, returned from
entry.columnvalues (as already suggested)?

--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
Success! Thank you all for the inspiration

Dim arr As Array = Ctype(entry.ColumnValues, Array)
Console.WriteLine(arr.GetValue(0).ToString)

entry.ColumnValues is an Array! An Array of variants
(objects)
 
Back
Top