子例程中可选控件的默认值有问题 [英] Problem in default values of optional controls in a sub routine

查看:42
本文介绍了子例程中可选控件的默认值有问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个默认值为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.
Collapse

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



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



When I called this subroutine in my program as

Collapse

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
Collapse

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)

推荐答案

功能ActivateControls可能不会检查是否该参数是否为空,仅假设txt和txt2是对有效TextBox控件的引用.

祝你好运!

附言即使错误消息很清楚这里发生了什么,您仍然会反复问同样的问题...
Probably the function ActivateControls doesn''t check whether the parameter are nothing or not and simply asumes that txt and txt2 are references to valid TextBox controls.

Good luck!

Ps. you keep asking the same question over and over even though the error message is quite clear about what''s going on here...


这篇关于子例程中可选控件的默认值有问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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