tags:

views:

140

answers:

1

Note the argument of the function is named strToothpaste. When the function is called, the variable that's passed in uses the same name.

Private Sub DoThis()
  Dim strToothpaste as String
  Dim booSmellsFunny as Boolean
  booSmellsFunny = fnc_Fragrance(strToothpaste)
End Sub
--------------------------
Private Function fnc_Fragrance(strToothpaste As String) as Boolean
  If strToothpaste Like "Dr Watson's" Then
     fnc_Fragrance = True
  Else
     fnc_Fragrance = False
  End If
End Function
  • Is there ever a problem with re-using the name?
  • If variables aren't properly limited in scope, does echoing the names become hazardous?
  • If the above is true, then does that mean good scoping means the names can be echoed with no problem?
  • Does recursion affect anything? (Apart from double-checking the scopes ...)
+4  A: 
  1. No not at all, VBA is smart enough to determine that the parameter is a parameter scoped to the function
  2. Yes this could be dangerous, if you are in the habit of Option Expiclit Off, which is never good for your sanity.
  3. Yes names can be echoed with no problem with proper scoping.
  4. Not at all.

Hope this helps.

almog.ori
If I'm insane, it's not because I left Option Explicit off. Thanks though.
Smandoli
I infer that "tweaked" var names may have been necessary when I didn't understand or apply good scoping. Of course eventually I had to tighten up and I found "normalizing" my code is not only critically important but fun as well.
Smandoli