有默认值的函数怎么写啊?如果我给他参数,它就用我的参数,如果没有给它参数,它就使用默认的参数。
就像msgbox,它的声明msgbox(prompt, [buttons as vbmsgboxstyle = vbokonly],[title],[helpfile],[context]) as vbmsgboxresult
使用msgbox的时候
msgbox "hello"
msgbox "hello",vbAbortRetryIgnore
msgbox "hello",vbAbortRetryIgnore,"title"
都可以。我要写这样的函数应该怎么写啊?
Private Function fn(str As String = " ") as String
Private Function fn(【str As String = " "】) as String
都不行啊。怎么写才对?
就像msgbox,它的声明msgbox(prompt, [buttons as vbmsgboxstyle = vbokonly],[title],[helpfile],[context]) as vbmsgboxresult
使用msgbox的时候
msgbox "hello"
msgbox "hello",vbAbortRetryIgnore
msgbox "hello",vbAbortRetryIgnore,"title"
都可以。我要写这样的函数应该怎么写啊?
Private Function fn(str As String = " ") as String
Private Function fn(【str As String = " "】) as String
都不行啊。怎么写才对?
解决方案 »
- picture请教,谢谢!!!
- VB怎么样才能让程序运行时屏蔽CTRL+ALT+DEL和AIL+TAB的组合键,而且在推出程序时解除对组合键的屏蔽?
- vb中打开了word文档,但为什么不能往文档中添加文字 !!大家看看我的代码
- 如何实现与摄像头交互?
- 请问怎样把这个RSA算法制作成注册程序
- 关于Workbook的名字问题!急
- 如何把图片打成流放到SQL里面那??
- 怎样实现将图片平铺显示到picturebox上?不胜感激
- webbrower 超难问题。分不够可以再开巾加
- 如何让窗体显示在所有应用程序的前面?
- 把“VB中如何做到象QQ一样,把窗体放在屏幕边缘,就自动缩进去。”下面的代码转成vb2005的代码。
- 为什么有的循环不能执行
Private Function fn(Optional str As String = " ") as String
private function do(Optional str As String = "str") as String函数的形参[Optional] [ByVal | ByRef] [ParamArray] varname[( )] [As type] [= defaultvalue]
可选的。表示参数不是必需的。如果使用了该选项,则 arglist 中的后续参数都必须是可选的,而且必须都使用 Optional 关键字声明。如果使用了 ParamArray,则任何参数都不能使用 Optional 声明。
直接写多个函数名相同,参数不同的函数即可。