comparing string to Object - VB6 to VB.Net

R

Rich

Hello,

I am converting an app from VB6 to VB.Net and have
encountered the following problem. I have the following
loop which retrieves objects from a collection of objects.

Dim entry As Domino.NotesViewEntry
Dim obj As Object, str1 As String
....
For Each obj In entry.ColumnValues.ToString
If IsArray(obj) Then
str1 = obj(0) '<---problem with this line - vb6 syntax
Else
str1 = obj.ToString
End If
Next

the error message says Option Strict doesn't allow late
binding. What would be the correct syntax for handling
this?

I also had a problem with entry.ColumnValues (VB6
syntax). I added .ToSting but haven't tried this yet
(hope it works - entry represents a Lotus Notes document
in a Lotus Notes view - equivalent of a record in an rdbms
system).

TIA,
Rich
 
A

Armin Zingler

Rich said:
Hello,

I am converting an app from VB6 to VB.Net and have
encountered the following problem. I have the following
loop which retrieves objects from a collection of objects.

Dim entry As Domino.NotesViewEntry
Dim obj As Object, str1 As String
...
For Each obj In entry.ColumnValues.ToString
If IsArray(obj) Then
str1 = obj(0) '<---problem with this line - vb6 syntax
Else
str1 = obj.ToString
End If
Next

the error message says Option Strict doesn't allow late
binding. What would be the correct syntax for handling
this?
I also had a problem with entry.ColumnValues (VB6
syntax). I added .ToSting but haven't tried this yet
(hope it works - entry represents a Lotus Notes document
in a Lotus Notes view - equivalent of a record in an rdbms
system).

If you use ToString, the loop iterates through all chars in the string, so
str1 would have to be declared as Char - and obj(0) wouldn't make sense.
What is the type of the items in entry.ColumnValues?


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
R

Rich

I declared the variable entry as a Domino.NotesViewEntry
object. So entry represents a row of data in a Lotus
Notes View (similar to a record in a Sql Server view) with
columns/fields. In my scenario, the data is all text data
(numeric text, date text, and char text). If I leave
Option Strict off I can use the syntax below, but with
Option Strict on I run into problems, like late binding
issues, entry.ColumnValues is regard as a System.Object
object, etc. I have posted requesting syntax for using
Option Strict on with these issues:
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

<<

how can I handle this with Option Strict On in vb.Net?

Thanks,
Rich
 
G

Guest

Rich said:
I declared the variable entry as a Domino.NotesViewEntry
object. So entry represents a row of data in a Lotus
Notes View (similar to a record in a Sql Server view) with
columns/fields. In my scenario, the data is all text data
(numeric text, date text, and char text). If I leave
Option Strict off I can use the syntax below, but with
Option Strict on I run into problems, like late binding
issues, entry.ColumnValues is regard as a System.Object
object, etc. I have posted requesting syntax for using
Option Strict on with these issues:

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)
That's true - late binding is not allowed with option explicit on - which kinda sucks :(
anyway - you could use one of these:
str1 = DirectCast(entry.ColumnValues(0), String)
or
str1 = CType(entry.ColumnValues(0), String)
basically, both are casting functions..
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
this doesn't work because i dont think entry.ColumnValues is returning an array
and even if it did, you might have to do something like
Dim obj() As Object = entry.ColumValues()
but i'm not really sure about that..however, if entry.ColumnValues is return a
collection of some other objects, i dont think you can directly assign the collection
to an array of objects; i would think that wouldn't work even if you had option
explicit off.
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
the above statement works because in .NET all reference types are natively of type
'Object'; so you can assign any type to an object.
 

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