将“可选控件"的默认值设置为“无"时出错 [英] Error while setting Optional Controls default value to Nothing

查看:106
本文介绍了将“可选控件"的默认值设置为“无"时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个默认值为Nothing的子例程,并且当我运行该程序时,只有当我给出了包括可选值在内的所有参数时,它才能正确运行.如果我仅错过一个可选参数,则会出现错误,即对象引用"未设置为对象的实例.
这是我的子程序.

I make a the subroutine with a default value of Nothing and when I run the program it runs correctly only if i gave all the arguments including optional values. If i miss only one optional argument it gives the error that Object Reference not set to an instance of object.
Here is my subroutine.

Private Sub ActivateControls(rd As RadioButton, Optional  txt As TextBox = Nothing, txt2 As TextBox = Nothing)
End Sub


当我在程序中以
形式调用此子例程时


When I called this subroutine in my program as

ActivateControls(rdbtn,txt)


它给了我以下错误
对象引用未设置为对象的实例"
但是当我将此子例程编写为


It gives me the following error
"Object Reference not set to an Instance of an Object"
But when I write this subroutine as

ActivateControls(rdbtn,txt,txt2)


正确.
所以,请告诉我这个问题的解决方案是什么



如果有其他任何值,我可以将其设置为控件的默认值(如文本框,组合框)


It works right.
So, Please tell me what is the solution of this problem

OR

If there any Other value Except Nothing that I can set to default value of a control(Like textbox, combobox)

推荐答案

Private Sub ActivateControls(rd As RadioButton, Optional  txt As TextBox = Nothing, Optional txt2 As TextBox = Nothing)
End Sub



您忘记了txt2必需的第二个Optional(否则txt2也是必需的)

祝你好运!



You forgot the second Optional that is necessary for txt2 (or else txt2 is also mandatory)

Good luck!


兄弟我再次检查了我的代码,但是这里没有缺少可选关键字.发布时误将其遗漏在这里.
因此,希望对您有帮助,并保留以下代码.

Brother I have checked again my code but Optional Keyword is not missing there. It was missing here by mistake while posting.
So, I hope to you answer keeping in view the following code.

Private Sub ActivateControls(rd As RadioButton, Optional  txt As TextBox = Nothing, Optional txt2 As TextBox = Nothing)
End Sub


这篇关于将“可选控件"的默认值设置为“无"时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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