Link to home
Start Free TrialLog in
Avatar of dominica526
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 intAnotherIncrementOrDecrement a variable that is un-defined. I can't find any info anywhere. Is it magical or what?


Thanks!!!
ASKER CERTIFIED SOLUTION
Avatar of JesterToo
JesterToo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dominica526
dominica526

ASKER

Option Explicit! that was my problem. I feel kind of silly but now I understand it all. But I would like to know where the magic is. intAnotherIncrementOrDecrement is just a variable just like IntGrandTotal, variable names that you made up. But why does it append?

Thanks
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 + intAnotherIncrementOrDecrement <<<   >>> 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 + intAnotherIncrementOrDecrement" 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 intAnotherIncrementOrDecrement 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
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&#8217;t show how intAnotherIncrementOrDecrement was getting charged with values and therefore my app was not working correctly, and I thought intAnotherIncrementOrDecrement was some kind of function. Now I understand that:

IntGrandTotal = intGrandTotal + intAnotherIncrementOrDecrement

Could be

A = A + AchangingValueThatWillBeAddedtoAeachCycle

Thank you,


 
You're welcome, and thank you for the grade once again!
Lynn