By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,457 Members | 1,335 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,457 IT Pros & Developers. It's quick & easy.

problem with late binding (option strict on)

P: n/a
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).ToShortDate String" 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).ToShortDateS tring, String) = search Then
Return teller
End If
Next
Return -1
End Function

--
Message posted via http://www.dotnetmonster.com
Nov 21 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a
"Dieter Schwerdtfeger via DotNetMonster.com" <fo***@DotNetMonster.com>
schrieb:
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).ToShortDat eString" 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).ToShortDateS tring,
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)'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #2

P: n/a
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.

"Dieter Schwerdtfeger via DotNetMonster.c" wrote:
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).ToShortDate String" 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).ToShortDateS tring, String) = search Then
Return teller
End If
Next
Return -1
End Function

--
Message posted via http://www.dotnetmonster.com

Nov 21 '05 #3

P: n/a
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

--
Message posted via http://www.dotnetmonster.com
Nov 21 '05 #4

P: n/a
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
Nov 21 '05 #5

P: n/a
If dt.ToShortDateString = search.ToShortDateString Then
"Dieter Schwerdtfeger via DotNetMonster.c" wrote:
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

--
Message posted via http://www.dotnetmonster.com

Nov 21 '05 #6

P: n/a
oh, forgot to do the 2nd part of your reply cor :) lemme try to figure that out now

--
Message posted via http://www.dotnetmonster.com
Nov 21 '05 #7

P: n/a
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.

--
Message posted via http://www.dotnetmonster.com
Nov 21 '05 #8

P: n/a
oh, it's just the explanation :)

man, it's all so overwhelming, got so many things on my mind :s

--
Message posted via http://www.dotnetmonster.com
Nov 21 '05 #9

P: n/a
about the aditional information, ontstaan is a column in my database under table clubs...

--
Message posted via http://www.dotnetmonster.com
Nov 21 '05 #10

P: n/a
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

--
Message posted via http://www.dotnetmonster.com
Nov 21 '05 #11

P: n/a
"Chris Podmore" <Ch**********@discussions.microsoft.com> schrieb:
If dt.ToShortDateString = search.ToShortDateString Then


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

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

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.