后期绑定问题(选项严格) [英] problem with late binding (option strict on)

查看:66
本文介绍了后期绑定问题(选项严格)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个功能,我在我的数据库中搜索在特定日期制作的项目。行CType(dvClubs.Item(teller).Item(veld).ToShortDate String给我错误:选项严格禁止后期绑定。我在这里读了一些关于后期绑定的帖子,但我无法想象它出来了:这个代码与选项严格关闭,但我只是听说我们必须用严格选项编写我们的程序:/

我希望你们能帮助我


Public Function ZoekOntstaan​​(ByVal search As Date,ByVal veld As String)As Integer

for teller As Integer = 0 to dvClubs.Count - 1

如果CType(dvClubs.Item(出纳员).Item(veld).ToShortDateS tring,String)=搜索然后

返回出纳员

结束如果

下一页

返回-1

结束功能


-

留言通过 http://www.dotnetmonster.com

解决方案

" Dieter Schwerdtfeger通过DotNetMonster.com "< fo *** @ DotNetMonster.com>

schrieb:

我有这个功能,我在我的数据库中搜索
制作的项目在特定日期。线路
CType(dvClubs.Item(teller).Item(veld).ToShortDat eString给了我
错误:选项严格禁止后期绑定。我看了一些帖子
这里关于后期绑定但我无法弄明白:这个代码工作
选项严格关闭,但我只是听说我们必须编写我们的程序
选项严格:/
我希望你们能帮助我们

公共功能ZoekOntstaan​​(ByVal搜索日期,ByVal veld As
字符串)作为整数
对于出纳员作为整数= 0到dvClubs .Count - 1
如果CType(dvClubs.Item(出纳员).Item(veld).ToShortDateS tring,
String)=搜索然后
返回出纳员
结束如果



你可以删除''CType'',因为''ToShortDateString''已经返回了一个

字符串。也许你需要施放''dvClubs。物品(柜员)''和

''< ...> .Item(草堆)''。


-

MS Herfried K. Wagner

MVP< URL:http://dotnet.mvps.org/>

VB < URL:http://dotnet.mvps.org/dotnet/faqs/>


尝试:


您需要使用ToShortDateString将dvClubs.Item(出纳员).Item(veld)转换为使用ToShortDateString之前的DateTime,因为它的数据类型未知。

对于出纳员为整数= 0到dvClubs.Count - 1

Dim dt As DateTime = CType(dvClubs.Item(teller).Item(veld),

DateTime)

如果dt.ToShortDateString =搜索那么

返回

结束如果

下一页


希望这个帮助。

克里斯。


Dieter Schwerdtfeger来自DotNetMonster.c写道:

我有这个功能,我在我的数据库中搜索特定日期的项目。行CType(dvClubs.Item(teller).Item(veld).ToShortDate String给我错误:选项严格禁止后期绑定。我在这里读了一些关于后期绑定的帖子,但我无法想象它出来了:这个代码与选项严格关闭,但我刚刚听说我们必须用严格选项编写我们的程序:/
我希望你们能帮助我

公共功能ZoekOntstaan​​(ByVal搜索为日期,ByVal veld为字符串)作为整数
对于出纳员为Integer = 0到dvClubs.Count - 1
如果CType(dvClubs.Item(出纳员).Item(veld).ToShortDateS tring,String)=搜索然后
返回柜员
结束如果
下一页
返回-1
结束功能

- 通过 http://www.dotnetmonster.com 发布消息


好吧,现在我在dt上出错了.ToShortDateString =>选项严格禁止从字符串到目前为止的隐式转换

感谢您的帮助


公共功能ZoekOntstaan​​(ByVal搜索为日期,ByVal veld为字符串)As整数

对于出纳员为整数= 0到dvClubs.Count - 1

Dim dt As DateTime = CType(dvClubs.Item(teller).Item(veld),DateTime)

如果dt.ToShortDateString =搜索那么

返回柜员

结束如果

下一页

返回-1

结束功能


-

通过 http://www.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).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

解决方案

"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/>


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



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


这篇关于后期绑定问题(选项严格)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆