Click to See Complete Forum and Search --> : ASP/VBScript style question (functions)


Strogian
09-20-2004, 02:03 AM
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.

rock
09-20-2004, 09:59 AM
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.