ASP/VBScript style question (functions)

Sharky Forums


Results 1 to 2 of 2

Thread: ASP/VBScript style question (functions)

  1. #1
    Hammerhead Shark
    Join Date
    Feb 2001
    Posts
    1,612

    ASP/VBScript style question (functions)

    Code:
    Function bob(input)
    Dim string
    For Each string In input.Strings
    bob = bob & string
    Next
    End Function
     
    Function bob(input)
    Dim string, finalstring
    For Each string In input.Strings
    finalstring = finalstring & string
    Next
    bob = finalstring
    End Function
    Which one is better? My C background makes me want to do the second one, but what is more natural in ASP/VBScript? My concern is that just saying "bob = bob & string" might be slower than "finalstring = finalstring & string", similar to how 'Session("bob") = Session("bob") & string' would be slower.

  2. #2
    NullPointerException rock's Avatar
    Join Date
    Sep 2000
    Location
    York, PA
    Posts
    6,203
    I don't think the first one is any slower. In fact, it might be faster because there is one less Dim and one less assignment (though you'd never notice). But, the second one is certainly more readable with the explicit return assignment at the end. This is very common in VB code, and would recommend it.

    Open Source is free like a puppy is free.

    It's only when you look at an ant through a magnifying glass on a sunny day that you realise how often they burst into flames.

    Understanding Evolution

Posting Permissions

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