Get number of additions that lead to a specific sum with given summands Suppose you have $n$ variables. Each of these variables (e.g. $a$) have their own interval between $0$ and $a_i$ (whole numbers). The only rule is that all these variables have to add up to a given value $s$.
An example:
$n = 3$, so the three variables are $a$, $b$ and $c$
$a_i = 2$, so $0\le$ $a$ $\le2$
$b_i = 3$, so $0\le$ $b$ $\le3$
$c_i = 4$, so $0\le$ $c$ $\le4$
$s = 6$, so $a+b+c=6$
The 9 unique possible solutions for these given variables are the following (the order of the variables is still important, so solution 7 and solution 9 are not the same):
$a=0$    $b=2$    $c=4$
$a=0$    $b=3$    $c=3$
$a=1$    $b=1$    $c=4$
$a=1$    $b=2$    $c=3$
$a=1$    $b=3$    $c=2$
$a=2$    $b=0$    $c=4$
$a=2$    $b=1$    $c=3$
$a=2$    $b=2$    $c=2$
$a=2$    $b=3$    $c=1$
What is the correct formula or program to only get the number of unique, possible solutions for any value of $n$, $s$ and the other variables, which would be 9 in this case?

Suppose you have $k$ variables, and you want to add it up to $n$:
$$f_n(x) = \frac{1}{n!}\frac{d^n}{dx^n}\prod_{i=1}^k \frac{1-x^{a_i+1}}{1-x}$$
Then your solution is $f(0)$.
To come up with this, start with the generating functions for your constraints:
$$(1+x+...x^{a_i}) = \frac{1-x^{a_i+1}}{1-x}$$
Suppose we compute part of this product with your example:
$$(1+x+x^2)(1+x+x^2+x^3)(1+x+x^2+x^3+x^4)$$
Then multiply the $x$ from the first by the $x^2$ in the second and the $x^3$ in the last. This gives $x^6$, and corresponds to the $a=1,b=2,c=3$ solution. 
Then coefficient of $x^n$ in that product is the number of solutions. I used the derivative and factorial, then evaluation at $x=0$ to get this, but if you're using a CAS it probably has a more efficient coefficient function.
