替代vb6 IsMissing() [英] substitue for vb6 IsMissing()

查看:109
本文介绍了替代vb6 IsMissing()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用于非参考数据类型的函数参数...例如date或

boolean ....


如何确定是否在调用代码中没有指定参数?


在vb6中我们会使用IsMissing()函数...

for a function parameter of a non-reference datatype ... such as date or
boolean ....

how to determine if the parameter was not specified in the calling code ?

in vb6 we would have used the IsMissing() function ...

推荐答案

我认为..在VB.NET中没有IsMissing()。

相反...... VB.NET强制指定可选的默认值

参数。所以你可以设置可选的参数。默认值为Nothing / -1

/""根据数据类型的任何内容,如果调用者指定的值

是默认值/值(覆盖默认值),则检查函数内部。

ex。 -

私人函数ABC(Byval X为整数,可选Byval Y为整数= -1)

.....

.. ...

结束功能


~Kapil


" John A Grandy" < johnagrandy-AT-雅虎网络泡沫>在消息中写道

news:eR ************** @ TK2MSFTNGP09.phx.gbl ...
I think .. there is no IsMissing() in VB.NET.
Instead ... VB.NET enforces specifying of default value for optional
parameters. So you can set the optional param. default value to Nothing / -1
/ "" whatever as per the datatype and check inside the function if the value
is default / value (overrides default value) specified by the caller.
ex. -
private function ABC(Byval X as integer,Optional Byval Y as integer = -1)
.....
.....
end function

~ Kapil

"John A Grandy" <johnagrandy-at-yahoo-dot-com> wrote in message
news:eR**************@TK2MSFTNGP09.phx.gbl...
for a function parameter of非引用数据类型...例如date或
boolean ....

如何确定调用代码中是否未指定参数?
在vb6中,我们将使用IsMissing()函数...
for a function parameter of a non-reference datatype ... such as date or
boolean ....

how to determine if the parameter was not specified in the calling code ?

in vb6 we would have used the IsMissing() function ...



hi kapil,感谢您的回复。


i不认为你理解我的帖子。


i特别询问非引用类型变量,例如Date和

布尔值。这些类型的变量不能是Nothing - 因为它们不是
引用变量它们没有任何意义它们不引用任何对象 -

这是什么都没有表示。


如果我对一个可选的布尔类型函数使用默认值False

参数,然后尝试确定调用代码是否提供了<通过检查参数的值是否为False来判断
值,如果调用代码确实提供了值,则会导致

错误结果,并且该值=

错误。


" Kapil Joshi" < KA ********* @ persistent.co.in>在留言中写道

新闻:uw ************** @ TK2MSFTNGP11.phx.gbl ...
hi kapil, and thanks for the response.

i don''t think you understand my post.

i specifically asked about non-reference type variables, such as Date and
Boolean. these type of variables can not be Nothing -- since they are not
reference variables it makes no sense for them to not refer to any object --
which is what Nothing means.

if i use a default value of False for an Optional Boolean type function
parameter, and then attempt to determine if the calling code supplied a
value by checking if the parameter''s value is False, this leads to an
erroneous result if the calling code did supply a value , and that value =
False.

"Kapil Joshi" <ka*********@persistent.co.in> wrote in message
news:uw**************@TK2MSFTNGP11.phx.gbl...
我想..那里在VB.NET中没有IsMissing()。
相反...... VB.NET强制指定可选的
参数的默认值。所以你可以设置可选的参数。默认值为Nothing
/ -1 /""根据数据类型,如果
值是调用者指定的默认值/值(覆盖默认值),则检查函数内部。
ex。 -
私人函数ABC(Byval X为整数,可选Byval Y为整数= -1)
....
....
结束函数

〜卡皮尔

John A Grandy < johnagrandy-AT-雅虎网络泡沫>在消息中写道
新闻:eR ************** @ TK2MSFTNGP09.phx.gbl ...
I think .. there is no IsMissing() in VB.NET.
Instead ... VB.NET enforces specifying of default value for optional
parameters. So you can set the optional param. default value to Nothing / -1 / "" whatever as per the datatype and check inside the function if the value is default / value (overrides default value) specified by the caller.
ex. -
private function ABC(Byval X as integer,Optional Byval Y as integer = -1)
....
....
end function

~ Kapil

"John A Grandy" <johnagrandy-at-yahoo-dot-com> wrote in message
news:eR**************@TK2MSFTNGP09.phx.gbl...
用于非参考的函数参数datatype ...比如date或
boolean ....

如何判断参数是否未在调用代码中指定

在vb6中我们会使用IsMissing()函数...
for a function parameter of a non-reference datatype ... such as date or
boolean ....

how to determine if the parameter was not specified in the calling code ?
in vb6 we would have used the IsMissing() function ...




如果你真的需要知道是否参数是否通过,只需创建

两种方法......


公共子测试()

....

结束子

公共子测试(值为字符串)

....

end sub


我想2方法会做几乎相同的事情,然后可能会这样做

这样的事情


公共子test()

realTest("",true)

end sub

公共子测试(值为字符串)

realTest(价值,假)

结束子


priva te sub realTest(值为字符串,isDefaultString为布尔值)

...

end sub


" John A Grandy" ; < johnagrandy-AT-雅虎网络泡沫>在消息中写道

news:eR ************** @ TK2MSFTNGP09.phx.gbl ...
if you realy need to know if the parameter was passed or not, just create
two methods...

public sub test()
....
end sub
public sub test(value as string)
....
end sub

I suppose the 2 method will do almost the same thing, then maybe do
something like this

public sub test()
realTest("", true)
end sub
public sub test(value as string)
realTest(value, false)
end sub

private sub realTest(value as string, isDefaultString as boolean)
...
end sub

"John A Grandy" <johnagrandy-at-yahoo-dot-com> wrote in message
news:eR**************@TK2MSFTNGP09.phx.gbl...
for a function parameter of非引用数据类型...例如date或
boolean ....

如何确定调用代码中是否未指定参数?
在vb6中我们会使用IsMissing()函数......
for a function parameter of a non-reference datatype ... such as date or
boolean ....

how to determine if the parameter was not specified in the calling code ?

in vb6 we would have used the IsMissing() function ...



这篇关于替代vb6 IsMissing()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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