Originally Posted by
sgrondines
does the variable Val1 and Val2 become Value1 and Value2? or should the variables used be the same, ie. Val1 in the first routine stay as Val1 in the second sub routine and Val2 the same?
I think we should talk about this first. Each subroutine processes within its own scope. There's no need to name them the same or differently, they will not share information or collide. You do want to take care not to use the same name as globally scoped variables, constants, or other functions.
Originally Posted by
sgrondines
Shouldn't the first Sub AddValues actually be a Function?
It is a little easier to understand having it be a function, and I myself would write it as a function. That said, it doesn't necessarily have to be a function. Use a function when you want to get a value returned. Use a sub when you just want it to do a thing and don't care about having it return a value.
Here's a function implementation.
Note: It's best practice to declare the return type of your function as I did in my example, otherwise it'll be declared as a variant. then it will be hard to predict what kind of data you'll get back.
Bookmarks