problem with late binding (option strict on)

  • Thread starter Thread starter Dieter Schwerdtfeger via DotNetMonster.com
  • Start date Start date
D

Dieter Schwerdtfeger via DotNetMonster.com

I have this function where i search through my database for items that were made on a specific date. The line "CType(dvClubs.Item(teller).Item(veld).ToShortDateString" gives me the error : option strict on disallows late binding. I have read some posts here about late binding but I just can't figure it out :s This code worked with option strict off, but i just heard that we had to write our program with option strict on :/
I hope you guys can help me

Public Function ZoekOntstaan(ByVal search As Date, ByVal veld As String) As Integer
For teller As Integer = 0 To dvClubs.Count - 1
If CType(dvClubs.Item(teller).Item(veld).ToShortDateString, String) = search Then
Return teller
End If
Next
Return -1
End Function
 
Dieter Schwerdtfeger via DotNetMonster.com said:
I have this function where i search through my database for items that were
made on a specific date. The line
"CType(dvClubs.Item(teller).Item(veld).ToShortDateString" gives me the
error : option strict on disallows late binding. I have read some posts
here about late binding but I just can't figure it out :s This code worked
with option strict off, but i just heard that we had to write our program
with option strict on :/
I hope you guys can help me

Public Function ZoekOntstaan(ByVal search As Date, ByVal veld As
String) As Integer
For teller As Integer = 0 To dvClubs.Count - 1
If CType(dvClubs.Item(teller).Item(veld).ToShortDateString,
String) = search Then
Return teller
End If

You can remove the 'CType' because 'ToShortDateString' already returns a
string. Maybe you need to cast 'dvClubs.Item(teller)' and
'<...>.Item(veld)'.
 
Try:

You need to convert dvClubs.Item(teller).Item(veld) to a DateTime before
using the ToShortDateString as it's data type is unknown.

For teller As Integer = 0 To dvClubs.Count - 1
Dim dt As DateTime = CType(dvClubs.Item(teller).Item(veld),
DateTime)
If dt.ToShortDateString = search Then
Return
End If
Next

Hope this help.
Chris.
 
Well, now I've got an error on the dt.ToShortDateString => option strict on disallows implicit conversions from string to date
thanks for the help already

Public Function ZoekOntstaan(ByVal search As Date, ByVal veld As String) As Integer
For teller As Integer = 0 To dvClubs.Count - 1
Dim dt As DateTime = CType(dvClubs.Item(teller).Item(veld), DateTime)
If dt.ToShortDateString = search Then
Return teller
End If
Next
Return -1
End Function
 
Dieter

Normally this should be as far as I can see enough,
If DirectCast(dvClubs(teller)(veld),DateTime).Date = search.Date Then

Cast in the dataview the object at row(teller) and in that the item(veld) as
datetime and use in that the date part to compare with the date part from
the datetimefield Search

I hope this helps?

Cor
 
now i get an error at "If DirectCast(dvClubs(teller)(veld), Date).Date = search.Date Then"


Public Function ZoekOntstaan(ByVal search As Date, ByVal veld As String) As Integer
For teller As Integer = 0 To dvClubs.Count - 1
If DirectCast(dvClubs(teller)(veld), Date).Date = search.Date Then
Return teller
End If
Next
Return -1
End Function


An unhandled exception of type 'System.ArgumentException' occurred in system.data.dll

Additional information: onstaan is neither a DataColumn nor a DataRelation for table clubs.
 
oh, forgot to do the 2nd part of your reply cor :) lemme try to figure that out now
 
oh, it's just the explanation :)

man, it's all so overwhelming, got so many things on my mind :s
 
about the aditional information, ontstaan is a column in my database under table clubs...
 
Well, I just changed my table so that i don't have a full date like 15/02/1900 but i just made it an integer with the year in, so just 1900, a lot easier like this :)
thanks for all your help
 
Chris Podmore said:
If dt.ToShortDateString = search.ToShortDateString Then

In this case it would be better to compare the dates directly:

\\\
If dt = search Then
...
End If
///
 
Back
Top