Results 1 to 8 of 8

Thread: [RESOLVED] Using function name as return value

Threaded View

  1. #1

    Thread Starter
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Resolved [RESOLVED] Using function name as return value

    I've never done it like this, but I do see code that does pretty often. It seems like it would be bad practice, but also that it would be faster and not cause any problems.

    Example:
    vb Code:
    1. 'Example #1
    2. Private Function GenerateString(ByVal Length As Long) As String
    3.    
    4.     Dim l As Long
    5.    
    6.     For l = 1 To Length
    7.         GenerateString = GenerateString & Chr$(Int(Rnd * 255) + 1)
    8.     Next l
    9.    
    10. End Function
    11.  
    12. 'Example #2
    13. Private Function GenerateString(ByVal Length As Long) As String
    14.    
    15.     Dim l As Long
    16.    
    17.     GenerateString = Space$(Length)
    18.    
    19.     For l = 1 To Length
    20.         Mid$(GenerateString, l, 1) = Chr$(Int(Rnd * 255) + 1)
    21.     Next l
    22.    
    23. End Function

    vs.

    vb Code:
    1. Private Function GenerateString(ByVal Length As Long) As String
    2.    
    3.     Dim l As Long, strReturn As String
    4.    
    5.     For l = 1 To Length
    6.         strReturn = strReturn & Chr$(Int(Rnd * 255) + 1)
    7.     Next l
    8.    
    9.     GenerateString = strReturn
    10.    
    11. End Function
    Last edited by DigiRev; Sep 22nd, 2009 at 07:40 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width