您的位置:首页 > 编程语言 > VB

VBA_Excel_教程:过程,函数

2016-12-03 11:11 357 查看
Sub s1()

Debug.Print "s1"
'调用过程:无括号,加call提升可读性
s2
Call s2
End Sub

Sub s2()
Debug.Print "s2"
End Sub


函数当过程用完全没有问题

Function f1()
Debug.Print "f1"
f2
Call f2
End Function

Function f2()
Debug.Print "f2"
End Function


函数是可以有返回值的

Function f1()
Debug.Print "f1"
strRet = f2("B")
Debug.Print strRet
strRet = f3("C")
Debug.Print strRet

End Function

Function f2(inPara As String) As String
'函数返回值用【函数名】表示
f2 = "return f2 " & inPara
End Function

Function f3(inPara) '返回值、参数:加类型声明更安全,提升可读性
f3 = "return f3 " & inPara
End Function
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: