我一直在做一些代码审查,这段代码对我来说似乎很奇怪,因为它没有任何return语句:
Protected Function AddZero(ByVal vsInput As String) As String
If Len(vsInput) = 1 Then
AddZero = "0" & vsInput
Else
AddZero = vsInput
End If
End Function
Run Code Online (Sandbox Code Playgroud)
Visual Basic将函数名称视为返回值,直到函数结束才返回.在代码中,您可以看到AddZero(函数名称)根据if条件设置为两个值之一.这就是你如何确定返回的内容.