I have been trying all day to figure out how to add up numbers in a text global variable in order to help with some other complex sizing issues.

I have created a calendar agenda that has the ability to show multiple events per day. I have customized it in a way that one could hide or show however many events. Unfortunately, this makes adding a shape behind the whole thing a pain, since i need to calculate the height and width of the whole calendar. I have actually figured out the width. The height is more complicated. I have managed to figure out the maths involved: a for loop, some if/then statements, regexp. And now i have a text string with the number of elements showing in order to size the background rectangle (and other planned features).

The solution i have is in a text format. And adding "+" between the numbers does not add them up. It just concactinates all of the numbers and symbols.

This is what i have so far:

gv(totHeight)

`$(gv(tall)+gv(paddVert))*gv(numItems)+gv(padfTpBt)$`

- gv(tall) [80] is the height of each element. A number in the globals
- gv(paddVert) [0] is additional vertical padding added to each element. A number in the globals
- gv(numItems) [dynamic] you'll see in a minute. It is the total number of agenda elements. A text formula. The thing im having problems with.
- gv(padfTpBt) [0] is additional paddin to the top and bottom of the entire komponent. A number in the globals.

gv(numItems)

```
$tc(
reg,fl(
0, gv(shodays)-1, "i+1", "if(
ci(acount,a+i+d)+ci(ecount,a+i+d)<=gv(shoXRevn),
ci(acount,a+i+d)+ci(ecount,a+i+d),
mu(round,gv(shoXRevn))
)","+"
),"0",1
)$
```

- gv(shoDays) [7] is the number of days youd want listed in the agenda. This includes days with no events because i have weather forecast info for each day as well. The max number i chose is 14 days, but can be adjusted via A number in the globals.
- gv(shoXRevn) [3] is the max number of events to show per day (ex: if a day has 4 events, but you only want to see the first 2 on the komponent). I set max to 5 min to 1. This is the needle that is making my life difficult. Because each day could have different number of events. And i have it set up to be able to dynamically reduce that number via A number in the globals.

At any rate, the gv(numItems) actually works, but its output is a text string that outputs something like this "1+4+1+1+1+2+1+1+2+1+1+3+1+1". This actually tells me how many events per selected number of days, and if i reduced gv(shoXRevn) it reflects that by subtracting 1 from each number until reaching 1. So, if i adjusted gv(shoDays) to 3 and gv(shoXRevn) to 2, the output would be "1+2+1". Or 7 days and max 3 events would be "1+3+1+1+1+2+1". You get the idea.

Im just not sure how to output that text string to a number to be used by gv(totHeight) to calculate my total height. I kinda wish there was a math utility for sum $mu(sum, gv(numItems))$ which would parse its input like an array.

As an aside, if anyone has a different strategy to calculate total height for my situation, I'm all ears. Maybe an easier way to get the number of calendar events with CI using my constraints? Or a better way to write the for loop? Or better regex? Or maybe the stack group container and sub-containers have a way of telling you how big they are?

Thanks for taking the time to read.