VB函数带缺省参数,函数怎么写?怎么调?我见VB系统里的好多函数都带缺省参数,自已写不成功!请哪位帮帮忙!!!感谢不尽!
Public Function sys(a As strng, b As String)
If a <> "" Then
MsgBox "hhhhhhhhhhhh"
End If
If b <> "" Then
MsgBox "jjjjjjjjjjjj"
End If
End Function
'调用这个函数时
call sys(Myyumen,)
'出错!!
问题很菜,请不要笑我哦!帮我!
Public Function sys(a As strng, b As String)
If a <> "" Then
MsgBox "hhhhhhhhhhhh"
End If
If b <> "" Then
MsgBox "jjjjjjjjjjjj"
End If
End Function
'调用这个函数时
call sys(Myyumen,)
'出错!!
问题很菜,请不要笑我哦!帮我!
Function MyFunc(MyStr As String, Optional MyArg1 As _ Integer = 5, Optional MyArg2 = "Dolly")
MsgBox "a=" & a
MsgBox "b=" & b
End Function'调用这个函数时
call sys("aaa","bbb")
call sys("aaa")
比如 sys("test","world")这样子function的调用是不需要call的,sub才需要call.
function和sub的区别是,function是有返回参数,所以你这边的代码根本没有返回参数,根本没必要用function,你这是概念不清楚带有默认参数使用optional,比如下面举的例子
Public Sub sysFile(ByVal sFileName As String, Optional lShowMsg As Boolean = True)
当call这个sub只需要写成call sysFille("strFile")就可以
最后还是表示感谢!!!