[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 231
  • Last Modified:

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!!!
0
dominica526
Asked:
dominica526
  • 3
  • 2
1 Solution
 
JesterTooCommented:
Dominica... it IS a variable.  I used that to show an example of how to add one variable to another.  The example I showed in the other question was just an incomplete code fragment.  Here's a slightly more complete example that demonstrates how to accumulate a "grand total" in a Public/Global variable and do something with the intermediate "running totals" values.

If you have a specific problem you're working on, please post whatever code you may have and describe what you need it to do and where you're having trouble with it.


Public intGrandTotal As Integer
.
.
.
.
Sub SomeRoutine()
Dim x As Integer
Dim intAnotherIncrementOrDecrement As Integer
Dim intSomeValue As Integer
Dim intSomeOtherValue As Integer
.
.
.
For x = 1 to 3
   intSomeValue = 1234
   intSomeOtherValue = 4
   intAnotherIncrementOrDecrement = intSomeValue * intSomeOtherValue
   IntGrandTotal = intGrandTotal + intAnotherIncrementOrDecrement
'          do something here to display the "running total" being accumulated into the variable intGrandTotal
Next
0
 
dominica526Author Commented:
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
0
 
JesterTooCommented:
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
0
 
dominica526Author Commented:
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,


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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now