473,387 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

problem with late binding (option strict on)

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
11 1555
"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
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
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
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
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
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
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
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
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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: noone | last post by:
I like to write my code with optionstrict set to on, except for the late binding errors I get when there is a reason to change some value in a control on a postback, like: Label4.Text =...
1
by: Karl Lang | last post by:
Hi I've created a new configuration section in Web.Config to hold the connection string for my database. If I have Option Strict On I get a message "Option Strict On disallows late binding" when I...
5
by: eBob.com | last post by:
In another thread VJ made me aware of Tag. Fantastic! I've been wanting this capability for a long time. But it seems that I cannot use it with Option Strict On. In an event handler I have ......
30
by: lgbjr | last post by:
hi All, I've decided to use Options Strict ON in one of my apps and now I'm trying to fix a late binding issue. I have 5 integer arrays: dim IA1(500), IA2(500), IA3(500), IA4(500), IA5(500) as...
17
by: David | last post by:
Hi all, I have the following problem: my program works fine, but when I add option strict at the top of the form, the following sub fails with an error that option strict does not allow late...
4
by: Heinz | last post by:
Hi all, I use VB.net 2003 and want to export data to Excel. Target PCs still have Office 2000 so I could not use Microsofts PIAs. Instead I use the included Excel 10 COM DLL from Microsoft....
4
by: Rippo | last post by:
Hi I have the following console application and am attempting to late bind a class with option strict on! However of course I cant and I get the following error "Option Strict On disallows late...
2
by: GS | last post by:
I have installed the ms PIA for ofc XP, and followed the article http://support.microsoft.com/kb/247412/ trying to paste into a worksheet However I got late binding not allowed errors .......
7
by: Lynn | last post by:
Hello, I have a website that is working fine. I have just turned on "option strict" and am getting an error with the parts of my code. I have fixed everything but this section, which has me...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.