|
|
|
Many programmers don't realize that it is perfectly legal to use the name of a function inside the Function itself, as if it were a local variable. This trick often lets you avoid the declaration of a temporary variable, and sometimes can speed up the code. Take for example the following code: |
Click here to copy the following block | Function Max(arr() As Long) As Long Dim res As Long, i As Long res = arr(LBound(arr)) For i = LBound(arr) + 1 To UBound(arr) If arr(i) > res Then res = arr(i) Next Max = res End Function |
You can make it more concise by getting rid of the res variable: |
Click here to copy the following block | Function Max(arr() As Long) As Long Dim i As Long Max = arr(LBound(arr)) For i = LBound(arr) + 1 To UBound(arr) If arr(i) > Max Then Max = arr(i) Next End Function |
You can even pass the function name by reference to another routine, or as an argument of an API function.
|
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
|
|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|