dominica526
asked on
intAnotherIncrementOrDecrement
This is a very powerful Function, Method or what? Where can I get info on it. JesterToo gave it to me and it only works on one PC. The other PC (the one I need it to work on) thinks it is intAnotherIncrementOrDecre ment a variable that is un-defined. I can't find any info anywhere. Is it magical or what?
Thanks!!!
Thanks!!!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi, Dominica..
Option Explicit just ensures that you don't try to use a variable that you haven't declared... primarily, it keeps you from mistyping a variable name in the code and accidentally using a different variable from the one you intended to use... this kind of error is often difficult to find in a large program because the code compiles just fine.
>>> IntGrandTotal = intGrandTotal + intAnotherIncrementOrDecre ment <<< >>> But why does it append? <<<
This statement "appends" (actually, with numeric variables, it's more properly called "adds"... "appends" implies concatenation which could also be termed "addition of strings") because of the "+" operator (or any other mathematical operator AND because the variable name that is receiving the result is also named on the right side of the "=". In other words, the variable is participating in the expression. In the case of "IntGrandTotal = intGrandTotal + intAnotherIncrementOrDecre ment" if you just look at the right hand expression we are taking the existing value of intGrandTotal and adding to it the value of the variable intAnotherIncrementOrDecre ment then storing that result back into intGrandTotal. The example in my earlier comment does this 3 times in the "For...Next" loop so the final value, in that example would be (1234 * 4) * 3, or 14808. If you run this in the VB debugger and single-step through each line of code you can see how it works.
The logic still replaces the value in intGrandTotal but not until it has first used it's current value in order to calculate its replacement value. The statement is executed in such a manner that the "assignment, or replacement, operation" is carried out as the last step. This allows the expression to refer to its current value before it is replaced.
Does this help clarify the process?
-- Lynn
Option Explicit just ensures that you don't try to use a variable that you haven't declared... primarily, it keeps you from mistyping a variable name in the code and accidentally using a different variable from the one you intended to use... this kind of error is often difficult to find in a large program because the code compiles just fine.
>>> IntGrandTotal = intGrandTotal + intAnotherIncrementOrDecre
This statement "appends" (actually, with numeric variables, it's more properly called "adds"... "appends" implies concatenation which could also be termed "addition of strings") because of the "+" operator (or any other mathematical operator AND because the variable name that is receiving the result is also named on the right side of the "=". In other words, the variable is participating in the expression. In the case of "IntGrandTotal = intGrandTotal + intAnotherIncrementOrDecre
The logic still replaces the value in intGrandTotal but not until it has first used it's current value in order to calculate its replacement value. The statement is executed in such a manner that the "assignment, or replacement, operation" is carried out as the last step. This allows the expression to refer to its current value before it is replaced.
Does this help clarify the process?
-- Lynn
ASKER
Hey Lynn,
Yes it does and thank you very much for taking the time to explain. The Option Explicit issue was a silly one, but I was having a difficult time understanding the concept based on the first example code that didn’t show how intAnotherIncrementOrDecre ment was getting charged with values and therefore my app was not working correctly, and I thought intAnotherIncrementOrDecre ment was some kind of function. Now I understand that:
IntGrandTotal = intGrandTotal + intAnotherIncrementOrDecre ment
Could be
A = A + AchangingValueThatWillBeAd dedtoAeach Cycle
Thank you,
Yes it does and thank you very much for taking the time to explain. The Option Explicit issue was a silly one, but I was having a difficult time understanding the concept based on the first example code that didn’t show how intAnotherIncrementOrDecre
IntGrandTotal = intGrandTotal + intAnotherIncrementOrDecre
Could be
A = A + AchangingValueThatWillBeAd
Thank you,
You're welcome, and thank you for the grade once again!
Lynn
Lynn
ASKER
Thanks